odavy
odavy

Reputation: 485

jquery this and other elements

OK, going rond in circles again - I'm sure the answer will be obvious. Just not to me :)

I can't seem to specify this as one target amongst a few targets for a function:

$(this, "elem1, elem2").doStuff()

I just want to doStuff() to a pair of elements, one of which is this. I can only get it to work if I explicitly name the elements, ie...

$("elem1, elem2, elem3").doStuff() 

...works fine. But I can't seem to get it to work if I want to include this in the list. I have to write one line just for this, and another for elem1 elem2 etc.

All help greatly appreciated. Thanks.

Upvotes: 2

Views: 1103

Answers (1)

cletus
cletus

Reputation: 625097

If I understand you correctly, you can use add() to add this to the jQuery object:

$("#elem1, #elem2").add(this).doStuff();

Or in reverse:

$(this).add("#elem1, #elem2").doStuff();

or even:

$(this).add("#elem1").add("#elem2").doStuff();

Upvotes: 5

Related Questions