Here's a quickie:
Is there a better jquery alternative to remove next all, including ($this)?
So far, this works for me: $(this).nextAll().remove();$(this).remove();
If you want to chain your calls then there are a few options however it doesn't change much in the way of performance:
$(this).nextAll().remove().end().remove();
$(this).nextAll().add(this).remove();
$(this).nextAll().andSelf().remove();
.end()
:
End the most recent filtering operation in the current chain and return the set of matched elements to its previous state.
http://api.jquery.com/end
.add()
:
Add elements to the set of matched elements.
http://api.jquery.com/add
.andSelf()
:
Add the previous set of elements on the stack to the current set.
http://api.jquery.com/andself
$(this).nextAll().andSelf().remove();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With