Consider following code:

<body>
    <script>
        $elem = $(".cRed");
        $elem.addClass("cBrown").removeClass(".cRed");
    </script>
    <div class="cRed cBlue">Something</div>

    <script>
        $elem = $(".cRed");
        $elem.toggleClass("cBlue cBrown");
        $elem.toggleClass("cRed  cBrown");
    </script>

</body>
What classes will be added to <div> element after the page fully loaded?
Explanation
   
 $elem = $(".cRed");
    $elem.addClass("cBrown").removeClass(".cRed"); // will do nothing, because there is no div element at that moment.
//and
    $elem.toggleClass("cBlue cBrown"); // add class "cBlue cBrown"
    $elem.toggleClass("cRed  cBrown"); // remove (toggle) class

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Cosmo
Sign Up Now
or Subscribe for future quizzes