我正在尝试查找下一个标题之前的所有内容。标题标题可以是h2、h3、h4、h5 甚至 h6。也就是说,在 main 和标题之间,它可能有许多其他元素或单个元素,因此不能选择它们直到下一个标题。
我怎么能做到这一点?
这是我目前的方法,它只在h4之前找到
$("main").parent().nextUntil("h4").each(function(){
console.log($(this).html())
})
使用标题选择器
$("main").parent().nextUntil(":header").each(function(){
console.log($(this).html())
})
在nextUntil()中使用多重选择器,例如,
$("main").parent().nextUntil("h2,h3,h4,h5,h6").each(function(){
console.log($(this).html())
})