Javascript examples for jQuery Selector:class
To select multiple classes using .class selector, seperate each class with a comma.
The following code shows how to select all elements with class "intro", "demo" or "end":
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $(".intro, .demo, .end").css("background-color", "yellow"); });// w ww . j ava 2 s. c om </script> </head> <body> <h1 class="intro">Welcome to My Homepage</h1> <p class="intro">This paragraph has class "intro".</p> <p class="intro">This paragraph has class "intro".</p> <p>This is a paragraph.</p> <p class="demo">This paragraph has class "demo".</p> <p class="demo">This paragraph has class "demo".</p> <p>This is another paragraph.</p> <p class="end">This paragraph has class "end".</p> <p class="end">This paragraph has class "end".</p> </body> </html>