I have a list of items that I’m iterating over. Each list item has the following HTML or some variation.
<li>
<input name=“technology1” id=“beadarray” type=“radio” value=“cat222” />
<label for=“beadarray”> BeadArray* cat222</label>
</li>
In jQuery I then append a set of parentheses to every item resulting in this when viewed in Firebug…
<li>
<input name=“technology1” id=“beadarray” type=“radio” value=“cat222” />
<label for=“beadarray”> BeadArray* cat222</label>
(
<span class=“counter”></span>
)
</li>
Now I can target the span (e.g. to insert a count), except…
When I try to traverse from the span to the radio button by using…
var test = thisCounter.prev().prev();
everything works fine. However, the next time a designer adds a div or a span after the label, I’m screwed.
I would like to use…
var test = thisCounter.prev(“selector”);
to specifically target the previous radio button. However, everything I’ve tried fails (returns a value of test as undefined). e.g. prev(“:radio”), prev(“input[name=‘technology1’]”), etc.
Any idea why my selectors don’t seem to work properly when passed to the prev() function?