Trying to use JQuery to scroll through a ul li list using class next and class prev e.g.
<ul class="selectoption">
<li> Item 1</li>
<li> Item 2</li>
<li> Item 3</li>
<li> ... </li>
</ul>
<a href="" class="next">Next</a>
<a href="" class="prev">Back</a>
Only thing is I only want the selected li to be visible. So somehow need to index the li's? Help much appreciated - thanks in advance
This should do it:
Try something like:
With the data object in jQuery, you can associate any kind of javascript data with a dom element. I have used this to save the state of the list.
You might want to add guards for the first and last item in the next / previous steps.
If you want your index, use the following:
Although I would look at Tatu Ulmanen's answer instead.