Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery multiple selectors, "AND" operator

The followingcode will fire alert to the click event for elements with Class = a.cssPauseAll OR attribute = historyID

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

});

How can I use multiple selectors using an AND operator?

which means, the elements with the a.cssPauseAll class AND historyID attribute?

like image 814
RollRoll Avatar asked Oct 10 '12 00:10

RollRoll


2 Answers

Just remove the , from your selector:

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

historyID is not a valid attribute you can use data-* attribute instead:

$(document).on("click","a.cssPauseAll[data-historyid]", function () {
like image 77
undefined Avatar answered Sep 22 '22 08:09

undefined


the elements with the a.cssPauseAll class AND historyID attribute

Use the following selector:

a.cssPauseAll[historyID]

Test it yourself - http://jsfiddle.net/SrNDt/

Note: Commas separate selectors and therefore behave as a logical OR. Chaining expressions into a single selector behave as a logical AND.

like image 28
Jason McCreary Avatar answered Sep 18 '22 08:09

Jason McCreary