Lukáš Řádek Lukáš Řádek - 1 year ago 88
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.

Answer Source

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


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download