The problem with the approach you're using:
$(this, '#foo')
JS Fiddle demo.
Is that this is a context-aware selection, searching for this
within the #foo
element (and is identical to $('#foo').find(this)
), which is valid within jQuery, though I'd imagine somewhat pointless (given that you already have a reference to this
(I assume, though if not this
might be the window
)).
In all honesty I'm not entirely sure why the selector 'works' at all, unless given the this
node jQuery simply discards the context, given that it already 'knows' where the this
node is and has a reference.
To add to a selection:
$(this).add('#foo');
JS Fiddle demo.
Or (conversely):
$('#foo').add(this);
JS Fiddle demo.
References: