Error jquery background color

1

I have the following code, but I change the background color of the body, I think it must be something of the scope, because it does not give me any error.

I thought about putting body onLoad='setThemes();' , but it says:

setThemes is not defined at onload

I clarify that the .js is separated from the html, as for the other functions as settings.darkTheme = true; , if you do it correctly.

<select id="themes" class="form-control">

<option value="agar" selected>Agar Theme</option>
<option value="slow">SlowMotion Theme</option>
<option value="psyco">Psyco Theme</option>
<option value="ogar">Ogar Theme</option>

                  </select>

// Themes functions
$(document).ready(function() {
    function setThemes() {

        gg = document.getElementById('themes');
        g2 = gg.options[gg.selectedIndex].value;

        if (g2 == 'agar') {

            settings.darkTheme = false;
        } else if (g2 == 'psyco') {
            settings.darkTheme = true;

            $(function() {
                $("body").css('background-color', 'blue !important');
            });

        } else if (g2 == 'slow') {

        } else if (g2 == 'ogar') {

        }

    }
    $("#themes").on("change", setThemes);
});
    
asked by Eduardo Sebastian 04.05.2017 в 12:40
source

1 answer

3

To change the background color of the body you just have to do:

 $("body").css('background-color', 'blue');

See the example:

var settings = {};

// Themes functions
$(document).ready(function() {
    function setThemes() {

        gg = document.getElementById('themes');
        g2 = gg.options[gg.selectedIndex].value;

        if (g2 == 'agar') {

            settings.darkTheme = false;
        } else if (g2 == 'psyco') {
            settings.darkTheme = true;

            $("body").css('background-color', 'blue');

        } else if (g2 == 'slow') {

        } else if (g2 == 'ogar') {

        }

    }
    $("#themes").on("change", setThemes);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="themes" class="form-control">

<option value="agar" selected>Agar Theme</option>
<option value="slow">SlowMotion Theme</option>
<option value="psyco">Psyco Theme</option>
<option value="ogar">Ogar Theme</option>

                  </select>
    
answered by 04.05.2017 в 13:03