This code works as I need:
$('input[class="plus"], input[class="minus"]').mousedown(function () {
//..doing something
});
What I wanted is something like:
$('input[class="plus minus"]').mousedown(function () {
//..doing something
});
or like:
$('input[class="plus"][class="minus"]').mousedown(function () {
//..doing something
});
The selector should choose any input, having either plus class or minus.
There must be some other syntax, but I don’t know one.
I’d recommend:
…so that other classes on the inputs don’t make you skip them. If you use the attribute equals selector (your
input[class="plus"]), it will only match if the only class on theinputis"plus". So it would match<input class="plus">but not<input class="plus foo">. Normally you want the flexibility of having other classes on the element.Alternately, you could do this:
…but it would be likely to be less efficient: First it would make jQuery look up all
inputelements, and then separately filter the result to just the ones with those classes. So I wouldn’t recommend it.