So I have a jquery selector and I am chaining many methods as well as using a toggle

.toggle() is used to display or hide the matched elements. So to just toggle the background, you can try this

    var initial = 'rgb(147, 233, 190)';
    var red     = 'rgb(255, 0, 0)';
    var black   = 'rgb(0, 0, 0)';

        "background-color": initial,
        "color": "white",
        "text-align": "center",
        "font-size" : "xx-large"
        if( $(this).css('background-color') === initial ){
            $(this).css('background-color', red);
        }else if( $(this).css('background-color') === red ){
            $(this).css('background-color', black);
            $(this).css("background-color", initial);
<script src=""></script>
<header style="height:50px;"></header>

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top