I have a DOM structure that looks like this:
<div class="chapter">
<section></section>
<section></section>
</div>
<div class="chapter">
<section></section>
<section></section>
<section class="current"></section>
<section></section>
</div>
<div class="chapter">
<section></section>
<section></section>
<section></section>
<section></section>
</div>
I want to get the index number of the section with a class of "current", across all sections. In this example the index of that would be 5, since it's the 5th section tag and contains a class of current.
How do I get this with jQuery?
I've started with this to get a list of all sections in the dom:
var sections = $('section');
I've tried things like this to try and get the result I want:
alert($(sections+'.current').index());
That returns a js error.
What am I missing here? Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…