There are two procedures to select an element with multiple classes by using jQuery. Both the procedures are described below with the proper example.
Using filter() Method: By using filter() method we can filter out all the elements that do not match the selected criteria and those matches will be returned.
- Syntax:
$(selector).filter(criteria, function(index))
- Example:
<!DOCTYPE html><html><head><title>jQuery | Select an elementwith multiple classes</title><style>h1 {color: green;}body {text-align: center;}</style><scriptsrc=</script></head><body><h1>GeeksforGeeks</h1><h3>Select an element withmultiple classes</h3><divclass="geeks">GeeksforGeeks</div><divclass="geeks geeks1">jQuery</div><divclass="geeks1">Select an element withmultiple classes</div><divclass="geeks1 geeks">Using</div><divclass="geeks geeks1 geeks2">filter() method</div><script>$(document).ready(function(){$(".geeks").filter(".geeks1").css("background-color", "yellow");$(".geeks.geeks2").filter(".geeks1").css("background-color", "green");});</script></body></html>chevron_rightfilter_none - Output:

Using .class Selector: By using .class Selector specifies the class for an element to be selected. It should not begin with a number. It gives styling to several HTML elements.
- Syntax:
$(".class1.class2.class3...") - Example:
<!DOCTYPE html><html><head><title>jQuery | Select an elementwith multiple classes</title><style>h1 {color: green;}body {text-align: center;}</style><scriptsrc=</script></head><body><h1>GeeksforGeeks</h1><h3>Select an element withmultiple classes</h3><divclass="geeks">GeeksforGeeks</div><divclass="geeks geeks1">jQuery</div><divclass="geeks1">Select an element withmultiple classes</div><divclass="geeks1 geeks">Using</div><divclass="geeks geeks1 geeks2">.class Selector Method</div><script>$(document).ready(function(){$(".geeks1").css("background-color", "yellow");$(".geeks").css("background-color", "white");$(".geeks.geeks2").css("background-color", "green");});</script></body></html>chevron_rightfilter_none - Output:

Recommended Posts:
- jQuery | multiple classes Selector
- How to Add and Remove multiple classes in jQuery ?
- How to remove options from select element using jQuery ?
- How to add options to a select element using jQuery?
- How to select first element in the drop-down list using jQuery ?
- How to select html element using ID in jQuery when ID contains a dot character ?
- How to get N options from the <select> element using JQuery?
- How to select an element by name with jQuery?
- How to select and upload multiple files with HTML and PHP, using HTTP POST?
- How to Select Multiple Files using HTML Input Tag ?
- How to show/hide div element depending multiple values using Bootstrap and jQuery ?
- How to select ID that starts with certain character using jQuery ?
- How to fire an event on file select using jQuery ?
- How to select all on focus in input using JQuery?
- How to select all elements without a given class using jQuery ?
- How to select text nodes using jQuery ?
- How to select a div with a certain class using jQuery ?
- How to select all elements that contains some specific CSS property using jQuery ?
- How to Select a Range of Elements using jQuery ?
- How to select the last row of a table using jQuery ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

