Search code examples
visual-studio-cordovavisual-studio-2015multi-device-hybrid-apps

Simple JavaScript not working when changing color in the body


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


Solution

  • 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