[jQuery] tricky traversing question
hello,
i'm facing a complex traversing question, can you help?
I need to know the number of a specific element with class="column"
that are BEFORE my selected element.
So, say i have this html (see below) and i am in this selection:
$('#dsViewport h3').each(function(index){
...
$amountOfColumnsBefore = $(this).prev(".ds-column").length;
$url = $(this).href("#"+$amountOfColumnsBefore);
});
My method does not work: $amountOfColumnsBefore = $(this).prevAll(".ds-
column").length;
Here is my html.
<div class="dsViewport">
<div class="section">
<h3>2007</h3>
<div class="column">...</div>
</div>
<div class="section">
<h3>2006</h3>
<div class="column">...</div>
<div class="column">...</div>
<div class="column">...</div>
</div>
<div class="section">
<h3>2005</h3>
<div class="column">...</div>
</div>
<div class="section">
<h3>2004</h3>
<div class="column">...</div>
<div class="column">...</div>
</div>
</div>
Thanks for your help!
Alexandre