I can’t get my head around this. Seems to be easy.
<ul class="steps anchor">
<li><a href="#step-1" class="done" isdone="1" rel="1"><label class="stepNumber">1</label></a></li>
<li><a href="#step-2" class="disabled" isdone="0" rel="2"><label class="stepNumber">2</label></a></li>
<li><a href="#step-3" class="selected" isdone="1" rel="3"><label class="stepNumber">3</label></a></li>
<li><a href="#step-4" class="disabled" isdone="0" rel="4"><label class="stepNumber">4</label></a></li>
</ul>
What I want:
I want to select the current Li (class=”selected”) (=3)
And then want to get the rel of the previous LI which has class=”done”.
$(‘ul.steps li a.selected’).prev(‘li’).hasClass(‘done’).html()
I am stuck thinking this way. Maybe anyone can help me in the right direction?
Thanks
Edit: I said Li with class=”done”. But that has to be an :
What I want:
I want to select the current a (class=”selected”) (=3)
And then want to get the rel of the previous a which has class=”done”.
Edit2:
<ul class="steps anchor"> <li><a href="#step-1" class="done" isdone="1" rel="1"><label class="stepNumber">1</label></a></li> <li><a href="#step-2" class="done" isdone="1" rel="2"><label class="stepNumber">2</label></a></li> <li><a href="#step-3" class="done" isdone="1" rel="3"><label class="stepNumber">3</label></a></li> <li><a href="#step-4" class="disabled" isdone="0" rel="4"><label class="stepNumber">4</label></a></li> <li><a href="#step-5" class="disabled" isdone="0" rel="5"><label class="stepNumber">5</label></a></li> <li><a href="#step-6" class="selected" isdone="1" rel="6"><label class="stepNumber">6</label></a></li> </ul>
I have updated my Li structure. Now say I am at LI 6. I want to go to the previous LI with a[class=’done’]. So a[rel=3]. Your anwsers always give the first LI back (1).
If you want to select the element that way which is not efficient, you can use
prevAllall method:http://jsfiddle.net/pn72t/
Or: