Like Richard said, you can use .add().
But also note that all the lengths you mentioned are off by one. The .length
property of a jQuery object, just like a string or an array, is the actual
length, not the length minus one. Don't be thrown off by the fact that array
indexes start at [0] and so naturally the last *index* is [length-1].
So what you should expect after using .add() is a jQuery object with five
elements indexed [0] through [4], and .length=5.
-Mike
> From: lowtech
>
> <ul>
> <li id="foo">
> <ul>
> <li class="bar"></div>
> <li class="bar"></div>
> <li class="bar"></div>
> <li class="bar"></div>
> </ul>
> </li>
> </ul>
>
> function getNodes(e) {
> return $.extend(e, $(e).find('li.bar')); }
>
> var nodes = getNodes($('#foo'));
> console.log(nodes);
>
> ---------------------
>
> How do I merge these two objects? If I ran a console.log on
> just "$ (e).find('li.bar')", it would return an object with a
> length of 3 and those four elements and if i ran a
> console.log on just $(e), it would return a length of 0 and
> just that element.
>
> Instead I would like to see an object returned with a length
> of 4 and the #foo element and all the .bar elements attached.
>
> Please don't worry about the function or why i'm not just
> calling $ ('li#foo, li.bar').
>