Crazy Developer
Crazy Developer

Reputation: 27

How to combine multiple selectors?

How can I select multiple fields in jQuery? (DOMs is an object)

clearFields: function() {
    $(DOMs.inpDes, DOMs.inpVal).val("");
    $(DOMs.inpDes).focus();
},

I use this

$(DOMs.inpDes, DOMs.inpVal).val("");

Upvotes: 1

Views: 210

Answers (1)

trincot
trincot

Reputation: 350202

You can use the add method:

$(DOMs.inpDes).add(DOMs.inpVal).val("");

If these object properties are CSS selector strings, like ".myclass", then you can also concatenate them, like this:

$([DOMs.inpDes, DOMs.inpVal].join()).val("");

... or like this:

$(DOMs.inpDes + "," + DOMs.inpVal).val("");

Upvotes: 1

Related Questions