Delete two items on one line

Is there a way to complete this script in one line?

$(this).next("br").remove();
$(this).remove();

I tried $(this).remove().next("br").remove();, but this does not work, because we delete the item before we can find the next one.

+5
source share
3 answers

You can use addBack () (or its predecessor andSelf () before jQuery 1.8):

$(this).next("br").addBack().remove();

Alternatively, you can use end () to return to the previous set of matched elements:

$(this).next("br").remove().end()
       .remove();
+9
source
$(this).add( $(this).next("br") ).remove();
+3
source
$(this).next("br").addBack().remove();
+3
source

All Articles