RollRoll
RollRoll

Reputation: 8462

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?

Upvotes: 10

Views: 9153

Answers (3)

Jason McCreary
Jason McCreary

Reputation: 73001

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.

Upvotes: 3

Sushanth --
Sushanth --

Reputation: 55750

Try this

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

Just remove the comma,

Upvotes: 1

Ram
Ram

Reputation: 144689

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 () {

Upvotes: 9

Related Questions