jQuery multiple selector with $(this)

getelementbyid, jquery, jquery-selectors, multiple-instances, this

Solution

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.

Solution

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

`add("selector")`

- Docs : http://api.jquery.com/add/

- What it does : Add elements to the set of matched elements.

Problem

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.

Original source