0

when watching this tutorial, I tried to repro the JavaScript used in the beginning.

However when setting up the function

        function setRandomColor(e) 
        {
            var bodyElement = document.querySelector("body");
            bodyElement.style.background.Color = "yellow";
        }

the part

bodyElement.style.background.Color = "yellow";

does not run, simply because style is not shown as an option.

Per my reseach this is supposed to work. Therefore my question: Is this a bug or what?

Note that I am using Visual Studio 2015 with Apache Cordova, version 14.0.22609.0 (CTP6, I believe).

Thanks

Joey
  • 511
  • 6
  • 20

2 Answers2

1

You should use

bodyElement.style.backgroundColor
Kaless1n
  • 313
  • 2
  • 8
0

According to w3schools, the background attribute you are calling is not supported in HTML5.

To correctly call the background color, try:

bodyElement.style.backgroundColor = "yellow";

For more information:w3schools explanation

cdslijngard
  • 196
  • 1
  • 10
  • 1
    Thanks, that worked. However I wonder why .style was not available as an option when writing the code... – Joey Feb 26 '15 at 09:51
  • This could be a hiccup in the editor you use. I would recommend using PHPStorm, as it is a solid, widely used editor for HTML/CSS, JavaScript and other languages. – cdslijngard Mar 02 '15 at 10:20