Use a jQuery method to toggle between adding and removing the "important" class from the <p> element, when you click on it. - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:toggleClass

Description

Use a jQuery method to toggle between adding and removing the "important" class from the <p> element, when you click on it.

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("p").click(function(){
        $(this).toggleClass("important");
    });//from  w w  w  .  j av a2 s .com
});
</script>
<style>
.important {
    font-weight: bold;
    font-size: xx-large;
    background-color: yellow;
}
</style>
</head>
<body>

<p>This is a paragraph - Click me!</p>

</body>
</html>

Related Tutorials