Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can i have a multi class selector in jquery

Tags:

jquery

Can I do something like the below where I can have multiple classes trigger an event?

$('a.red a.blue a.green').click(function(event) 
{

});
like image 886
ian Avatar asked Aug 30 '10 02:08

ian


People also ask

Can we use multiple selectors in jQuery?

You can specify any number of selectors to combine into a single result. This multiple expression combinator is an efficient way to select disparate elements. The order of the DOM elements in the returned jQuery object may not be identical, as they will be in document order.

How many types of jQuery selectors are available?

So far we have covered only three standard jQuery Selectors.


1 Answers

Yes, you can use the comma as separator.

$('a.red, a.blue, a.green').click(function(event) {});
like image 54
BalusC Avatar answered Sep 28 '22 06:09

BalusC