Is there a way of completing this script in one line?
$(this).next("br").remove();
$(this).remove();
I tried $(this).remove().next("br").remove();
but this doesn't work because we're removing the element before we can find the next one.
You can use addBack() (or its predecessor andSelf() before jQuery 1.8):
$(this).next("br").addBack().remove();
Alternately, you can use end() to get back to the previous set of matched elements:
$(this).next("br").remove().end()
.remove();
$(this).add( $(this).next("br") ).remove();
$(this).next("br").addBack().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