From: Piotr K on
Ok, I tried simply everything that came to my mind and now I ran out
of ideas, but to the point - take a look at the code below

// GetStyle returns given style value (works fine)
document.getElementById("inner").style.backgroundColor =
GetStyle("box", "backgroundColor");
document.getElementById("box").style.backgroundColor = "transparent";

<div id="box" style="width: 100px; height: 100px; background-color:
Red">
<div id="inner" style="width: 50px; height: 50px"></div>
</div>

What this code do - it retrieves "background-color" style from "box"
element, assigns it to "inner" and then "box" background gets
transparent. Now the funny part - it works in every browser, except
Opera, where both elements gets transparent background. What's even
more funny, when I replace GetStyle(...) with string "Red" it works
fine (GetStyle also returns string). Can someone explain me what is
going on? It's so illogical that I'm starting to think that maybe this
is a bug in Opera..

Thanks for any help,
P.
From: Henry on
On Apr 22, 12:52 am, Piotr K wrote:
> Ok, I tried simply everything that came to my mind and now I ran
> out of ideas, but to the point - take a look at the code below
>
> // GetStyle returns given style value (works fine)
> document.getElementById("inner").style.backgroundColor =
> GetStyle("box", "backgroundColor");
> document.getElementById("box").style.backgroundColor = "transparent";
>
> <div id="box" style="width: 100px; height: 100px; background-color:
> Red">
> <div id="inner" style="width: 50px; height: 50px"></div>
> </div>
>
> What this code do - it retrieves "background-color" style
> from "box" element, assigns it to "inner" and then "box"
> background gets transparent. Now the funny part - it works
> in every browser, except Opera, where both elements gets
> transparent background. What's even more funny, when I
> replace GetStyle(...) with string "Red" it works fine
> (GetStyle also returns string). Can someone explain
> me what is going on? It's so illogical that I'm starting
> to think that maybe this is a bug in Opera..
>
> Thanks for any help,

I don't know what help you expect. You have not included the code
necessary for anyone else to even attempt to reproduce your symptoms,
let alone attribute cause and effect relationships to them. And no
matter how effective you assert your - GetStyle - function to be I bet
most would like to see the code in question and verify its suitability/
reliability for themselves.
From: pr on
Piotr K wrote:
> Ok, I tried simply everything that came to my mind and now I ran out
> of ideas, but to the point - take a look at the code below
>
> // GetStyle returns given style value (works fine)
> document.getElementById("inner").style.backgroundColor =
> GetStyle("box", "backgroundColor");

What is GetStyle()?

> document.getElementById("box").style.backgroundColor = "transparent";
>
> <div id="box" style="width: 100px; height: 100px; background-color:
> Red">
> <div id="inner" style="width: 50px; height: 50px"></div>
> </div>
>
> What this code do - it retrieves "background-color" style from "box"
> element, assigns it to "inner" and then "box" background gets
> transparent. Now the funny part - it works in every browser, except
> Opera, where both elements gets transparent background. What's even
> more funny, when I replace GetStyle(...) with string "Red" it works
> fine (GetStyle also returns string). Can someone explain me what is
> going on? It's so illogical that I'm starting to think that maybe this
> is a bug in Opera..

Maybe it is, maybe it isn't. Post the code for GetStyle() and we might
be able to tell.
From: Piotr K on
On 22 Kwi, 12:21, pr <p...(a)porl.globalnet.co.uk> wrote:
> Piotr K wrote:
> > Ok, I tried simply everything that came to my mind and now I ran out
> > of ideas, but to the point - take a look at the code below
>
> > // GetStyle returns given style value (works fine)
> > document.getElementById("inner").style.backgroundColor =
> > GetStyle("box", "backgroundColor");
>
> What is GetStyle()?
>
> > document.getElementById("box").style.backgroundColor = "transparent";
>
> > <div id="box" style="width: 100px; height: 100px; background-color:
> > Red">
> > <div id="inner" style="width: 50px; height: 50px"></div>
> > </div>
>
> > What this code do - it retrieves "background-color" style from "box"
> > element, assigns it to "inner" and then "box" background gets
> > transparent. Now the funny part - it works in every browser, except
> > Opera, where both elements gets transparent background. What's even
> > more funny, when I replace GetStyle(...) with string "Red" it works
> > fine (GetStyle also returns string). Can someone explain me what is
> > going on? It's so illogical that I'm starting to think that maybe this
> > is a bug in Opera..
>
> Maybe it is, maybe it isn't. Post the code for GetStyle() and we might
> be able to tell.

Here's the GetStyle code:

function GetStyle(obj, style) {
obj = document.getElementById(obj);

if(style == "opacity") return GetOpacity(obj);

if(obj.currentStyle) return obj.currentStyle[style];
else if(window.getComputedStyle) return getComputedStyle(obj,
"").getPropertyValue(style.replace(/[A-Z]/g, function(obj, ch) {return
"-"+style.charAt(ch).toLowerCase()}));
}

However I don't think this has anything to do with that strange
behaviour. In the example I posted earlier it returns simply "Red", so
in other words

GetStyle("box", "backgroundColor") == "Red"

When I use GetStyle, the background gets transparent under Opera, but
if I replace it with simply "Red" string everything works fine. I
thought there may be some kind of referencing going on under Opera,
but I tried even copying each character from GetStyle return value to
array and than joining it into completely new string - still the same
effect.
From: VK on
On Apr 22, 3:52 am, Piotr K <piotr.korzeniew...(a)gmail.com> wrote:
> document.getElementById("box").style.backgroundColor = "transparent";

"transparent" is an imaginary value. It was used in W3C docs to
describe an element that has no color property set, like "transparent
element", but it was not meant to be an actual string to assign to the
style. Now it is supported by some newer browsers due to misreading
some badly written W3C samples. Neither Opera not IE6 are one of them.

Never Ever In Your Life :-) put style rules to their default values by
any explicit assignment: because you never in your life can guess what
explicit assignment is expected by some particular UA (think of the
infamous table element display glitch). Always use empty string
instead: this way any UA will restore what it needs by itself.

document.getElementById('box').style.backgroundColor = '';