有没有办法在一行中完成这个脚本?
$(this).next("br").remove();
$(this).remove();
Run Code Online (Sandbox Code Playgroud)
我试过$(this).remove().next("br").remove();但是这不起作用,因为我们在找到下一个元素之前删除了元素.
你可以在jQuery 1.8之前使用addBack()(或它的前身andSelf()):
$(this).next("br").addBack().remove();
Run Code Online (Sandbox Code Playgroud)
或者,您可以使用end()返回上一组匹配元素:
$(this).next("br").remove().end()
.remove();
Run Code Online (Sandbox Code Playgroud)