Is there a possibility to add the children of elements in a jQuery set to the set without leaving the chain?
I.e., with leaving it would look like this:
var set = $('.some-elements');
set.add('*', set);
// or immediate ones only
set.add(set.children());
I’m looking for a way to do any of these without creating the interim set variable:
$('.some-elements').jqMagic("*");
(Of course one could write a “jqMagic” plugin for this. I just want to be sure, there isn’t this functionality in jQuery core.)
I believe AndSelf will let you do what you’re asking.
update with example:
Given the following html:
This code gives just the children (anchor tags in this case) a red border:
while this code (using andSelf()) includes the parent divs in the element list and therefore selects both the parent divs and the child divs – thus giving a merged set as you requested: