Lukáš Řádek Lukáš Řádek - 6 months ago 18
jQuery Question

jQuery multiple selector with $(this)

is there any way to make this work:

$(this, '#foo')

with that I want to select "this" element and #bar as well.
For selecting let's say two IDs, it is just as easy as
'#foo, #bar'
, but when I want one of those two to be "this" I cannot get it to work.


Problem with your approach

$(this, '#foo')

The above line will search for this inside an element with id set to foo, which isn't what you want here.


You can use add() for this :

var $el = $(this).add('#foo')

Now $el will contain $(this) & $("#foo") on which you can perform operations on.

More info on the methods used