有没有一种方法可以轻松地执行nextUntil,以便包含选择器匹配的元素?我有这个,只有在有 previous sibling 姐妹时才可以:
$("#content").find("h3:first").prev().nextUntil("ul:last").wrapAll("<div id='collapse'></div>");
最佳答案
删除 .prev()
,将 .nextUntil
替换为 .nextAll
并使用 .addBack()
选择器的末尾,如下所示:
$("#content").find("h3:first").nextAll("ul:last").addBack().wrapAll("<div id='collapse'></div>");
1.8 之前应该使用 andSelf
而不是 addBack
关于jQuery nextUntil,包括,不排除匹配的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9539243/