BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

jQuery multiple classes Selector

Last Updated: April 20, 2019 by Chaitanya Singh | Filed Under: jQuery

In the previous tutorial, we learned jQuery class selector. In this article, we will see how to select multiple classes using jQuery multiple classes Selector.

Syntax

Classes are mentioned inside the parenthesis, separated by commas and each class is prefixed with . (dot).

$(".class1, .class2, .class3")

The above selector will select all the elements with classes class1, class2 & class3.

jQuery multiple classes Selector Example

Lets take an example to understand how can we select multiple classes using the jQuery Selectors.

Here we have selected the elements with class cl1 and cl2 on a button click event and we are calling hide() method to hide these selected elements. In the following example the second para is marked with class cl2 and the Click Me! button element has the class cl1 so on the button click event these two elements are hidden from the screen, which you can see in the output below.

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $(".cl1, .cl2").hide();
  });
});
</script>
</head>
<body>

<h2>jQuery multiple classes selector example on BeginnersBook.com</h2>
<p>This is just a paragraph and I am writing this just for the sake of this example.</p>
<p class="cl2">This is another para in this example, just a plain text</p>
<button class="cl1">Click Me!</button>

</body>
</html>

Output:
Before the button is clicked:
jQuery multiple classes selector example
After the button is clicked:
jQuery multiple classes selector output

❮ PreviousNext ❯

Top Related Articles:

  1. jQuery html() method
  2. jQuery Multiple Elements Selector
  3. jQuery Events
  4. jQuery removeClass() Method
  5. jQuery Class Selector

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

jQuery Tutorial

  • jQuery Tutorial
  • jQuery Selectors
  • jQuery Events

jQuery Effects

  • jQuery Show & Hide
  • jQuery Fading
  • jQuery Sliding
  • jQuery Animate
  • jQuery stop()
  • jQuery Callback Function
  • jQuery Chaining

jQuery HTML/CSS

  • jQuery html()
  • jQuery addClass()
  • jQuery hasClass()
  • jQuery removeClass()
  • jQuery toggleClass()
  • jQuery after()
  • jQuery before()
  • jQuery append()
  • jQuery appendTo()
  • jQuery clone()
  • jQuery insertBefore()
  • jQuery insertAfter()
  • jQuery attr()
  • jQuery text()
  • jQuery val()
  • jQuery css()
  • jQuery prepend()
  • jQuery remove()
  • jQuery empty()
  • jQuery detach()

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap