Multiple jQuery selectors, AND operator

The following code will alert the click event for elements with the attribute class = a.cssPauseAll OR = historyID

 $(document).on("click","a.cssPauseAll,[historyID]", function () { alert($(this)); }); 

How to use multiple selectors using the AND operator?

What does it mean that elements with the attribute a.cssPauseAll class AND historyID ?

+8
jquery jquery-selectors
source share
3 answers

Just remove , from your selector:

 $(document).on("click","a.cssPauseAll[historyID]", function () { 

historyID not a valid attribute, you can use the data-* attribute data-* :

 $(document).on("click","a.cssPauseAll[data-historyid]", function () { 
+8
source share

elements with attribute a.cssPauseAll class AND historyID

Use the following selector:

 a.cssPauseAll[historyID] 

Check it out yourself - http://jsfiddle.net/SrNDt/

Note: Lock individual selectors and therefore behave like a logical OR . Expression chains in one selector behave like logical AND .

+3
source share

try it

 $(document).on("click","a.cssPauseAll[historyID]", function () { 

Just remove the comma ,

+1
source share

All Articles