document.bgColor in Opera

J

Just One

Hi,

I'm trying to dynamically assign a div background the value of the document
background with a code like this:

var menuDiv = '<div style="visibility:hidden; ';
menuDiv = menuDiv + 'background-color:';
menuDiv = menuDiv + document.bgColor;
menuDiv = menuDiv + '></div>';

In IE and FF, that's working great but not in Opera. I don't really think
Opera is very popular but still, I'm wondering if what I want is easily
achievable with this browser?

Thanks
 
R

Randy Webb

Just One said the following on 6/24/2007 9:08 AM:
Hi,

I'm trying to dynamically assign a div background the value of the document
background with a code like this:

var menuDiv = '<div style="visibility:hidden; ';
menuDiv = menuDiv + 'background-color:';
menuDiv = menuDiv + document.bgColor;

document.style.backgroundColor;

And then make sure it is defined as background-color in the CSS of the
body element.
 
S

scripts.contact

Just said:
Hi,

I'm trying to dynamically assign a div background the value of the document
background with a code like this:

var menuDiv = '<div style="visibility:hidden; ';
menuDiv = menuDiv + 'background-color:';
menuDiv = menuDiv + document.bgColor;
menuDiv = menuDiv + '></div>';

Randy's suggestion will not work, try this:

var menuDiv = '<div style="visibility:hidden; ';
menuDiv = menuDiv + 'background-color:';
menuDiv = menuDiv +
(document.bgColor||
getComputedStyle(document.body,null).backgroundColor||'transparent');
menuDiv = menuDiv + '></div>';
 
J

Just One

Cheers, scripts.contact! That works great, even though I don't quite know,
let alone understand that method. I guess being stuck with JS1.3 and old
browsers is the reason, have to fast-forward to version 1.5 and Gecko-based
DOM (as I understand both FF and Opera try adhering to it).
 
R

Randy Webb

scripts.contact said the following on 6/24/2007 2:51 PM:
Randy's suggestion will not work

Only because it should have been document.body.style.backgroundColor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top