Javascript examples for jQuery Method and Property:addClass
Add two classes to an element
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("p:first").addClass("intro note"); });// w w w. j a va 2 s . c o m }); </script> <style> .intro { font-size: 30px; color: red; } .note { background-color: blue; } </style> </head> <body> <button>Add two class names to the first p element</button> <p>This is a paragraph.</p> <p>This is another paragraph.</p> <p>This is another paragraph.</p> <p>This is another paragraph.</p> </body> </html>