Note that there are some explanatory texts on larger screens.

plurals
  1. POdocument.body.style.backgroundColor is undefined
    primarykey
    data
    text
    <p>I have a javascript function that is called when the user clicks a div to get the current background color (white on my laptop) of the web page:</p> <pre><code>&lt;div id="div1" onclick="checkbkcolor(id, 1)"&gt;Just testing the web page bk color &lt;/div&gt; </code></pre> <p>Here is the checkbkcolor() function:</p> <pre><code> &lt;head&gt; &lt;script type="text/javascript"&gt; // DOES NOTHING SO I COMMENTED IT OUT: document.body.style.backgroundColor = "red"; function checkbkcolor(id, val) { // THIS RETURNS NOTHING FOR THE COLOR -- the alert box // only says "the document.body.style.backgroundColor is: " // and nothing else alert("the document.body.style.backgroundColor is: " + document.body.style.backgroundColor); document.body.style.backgroundColor = "red"; // The alert box now shows 'red' for the color name, *AND* // the web page's background has turned all red alert("the document.body.style.backgroundColor is: " + document.body.style.backgroundColor); } &lt;/script&gt; &lt;/head&gt; </code></pre> <p>In other words: my web page background is white when the page appears BUT the document.body.style.backgroundColor is not set. </p> <p>So is my web page set to 'transparent'? </p> <p>I don't think so. To test, I added the following CSS background color and when the web page <em>first</em> appears, the entire background is yellow:</p> <pre><code> body { background-color: rgb(255,255,0); } </code></pre> <p>Now when my web page appears, it is no longer white (or transparent, whatever). The web page is yellow when it appears.</p> <p>AND STILL. The following code shows the background color is not set:</p> <pre><code> function checkbkcolor(id, region) { // THIS RETURNS NOTHING FOR THE COLOR alert("the document.body.style.backgroundColor is: " + document.body.style.backgroundColor); // same code other as above } </code></pre> <p>My assumption is that my research (4 hours worth) on 'bgColor', 'background', 'backgroundColor' were not helpful.</p> <p>Most of all I don't understand how the entire web page background can come up yellow when I set the 'body' in CSS to rgb(255,255,0) and yet the following alert box says the backgroundColor is NOT SET:</p> <pre><code> alert("the document.body.style.backgroundColor is: " + document.body.style.backgroundColor); </code></pre> <p>I need to know, when the page first appears, what the background color is. How?</p> <p>EDIT: I'm using the latest version of Firefox, version 22.0</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload