$(document).ready(function(){ //demonstrates the add class $("button").click(function(){ $("h1,h2,p").addClass("blue"); $("div").addClass("important"); }); //demonstrate the remove class $("#remove").click(function(){ $("h1,h2,p").removeClass("blue"); }); });
<h1>Heading 1</h1> <h2>Heading 2</h2> <p>This is a paragraph.</p> <p>This is another paragraph.</p> <div>This is some important text!</div> <br> <button>Add classes to elements</button> <button id="remove">remove classes to elements</button>
.blue { color:blue; } .important{ color:red; }