Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery pushStack

I need some help to understand pushStack

Here I've made an example where the results using it or not are the same http://jsfiddle.net/Bz5n9/2/ so I think i really didn't get what is it for.

Thanks!

like image 452
Diego Avatar asked Dec 05 '25 15:12

Diego


1 Answers

You're currently adding to the collection, pushing a new collection on the stack that's already the result (you could just return the result of this.add()). What this does is instead of pushing .b elements on the stack as a new element, it pushes a new set with .b elements and the #2 <li> you started with.

Instead, you instead should pass the elements directly (no .add() call), like this:

return this.pushStack(newCollection, "agregate", "");

You can test it out here.

like image 108
Nick Craver Avatar answered Dec 08 '25 03:12

Nick Craver



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!