我需要获取子元素 h2 之间的所有 .section 元素。我的代码切换所有元素;untilNext(ab) 不选择具有后代 b 的元素。我需要另一种方法还是我没有看到的错误?
html: '
<div class='section' id='section-4'>
<div class='docs'>
<div class='octowrap'>
<a class='octothorpe' href='#section-4'>#</a>
</div>
<h2>todo <br></h2>
<p>main.html <br></p>
</div>
<div class='code'>
<div class="highlight"><pre><span class="n">colorific</span></pre></div>
</div>
</div>
<div class='clearall'></div>
<div class='section' id='section-5'>
<div class='docs'>
<div class='octowrap'>
<a class='octothorpe' href='#section-5'>#</a>
</div>
<p>containers <br></p>
</div>
<div class='code'>
</div>
<div class='clearall'></div>
<div class='section' id='section-6'>
<div class='docs'>
<div class='octowrap'>
<a class='octothorpe' href='#section-6'>#</a>
</div>
<h2>nextH2</h2>
</div>
<div class='code'>
<div class="highlight"><pre><span class="n">blah</span></pre></div>
</div>
</div>
<div class='clearall'></div>
翻译为:
great-grandparent <div class='section' id='section-18'>
grandparent <div class='docs'>
parent <div class='octowrap'>
* <a class='octothorpe' href='#section-18'>#</a>
h2 <h2> </h2>
js:
$(function(){ |
$('.octothorpe').on({ |- vimwiki_docs.py (/home/solver/webpag1)
click:function(e){ |
e.preventDefault(); |- vimwiki_docs.html (/home/solver/webpag1/docs)
var $pfold = $(this).closest('.octowrap').siblings('p'); |
var $cfold = $(this).closest('.docs').siblings('.code'); |- knowl.js (/home/solver/webpag1/docs)
var $sector = $(this).closest('.section'); ||- global
var $h2 = $sector.nextUntil('.section > h2'); ||| knowl_id_counter
//var $h2 = $sector.nextAll('div').each(function(){ ||
// //this within iteration refers to h2 div element ||- function
// if ($(this).is('h2')) { ||| knowl_click_handler
// return false; |
// }}) | ~
| ~
//});//close each() | ~
$pfold.toggleClass('fold'); | ~
$cfold.toggleClass('fold'); | ~
$h2.toggleClass('fold'); | ~
//console.log('h2', $h2) | ~
//if (!$h2.hasClass("fold") && !$pfold.hasClass("fold") && !$cfold.hasClass("fold")) { | ~
// $cfold.slideUp().addClass('fold'); | ~
// $pfold.slideUp().addClass('fold'); | ~
// $h2.slideUp().addClass('fold'); | ~
//} | ~
//else { | ~
// $cfold.slideDown().removeClass('fold'); | ~
// $pfold.slideDown().removeClass('fold'); | ~
// $h2.slideDown().removeClass('fold'); | ~
//} | ~
| ~
}}); | ~
});
我尝试了 nextUntil 和 nextAll 并返回 false ......不走运!
任何帮助是极大的赞赏。谢谢