What is best way to navigate select option using next/previous button with jquery? I have a select list when change also changes some div. Instead of just a dropdown, I want to have a next and previous button on the left and right sides of the select list.
I cant really figure out, i tried attr but only working if I manually type the attributes.
<button type="button" id="prev">Previous</button>
<select id="mycars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
<button type="button" id="next">Next</button>
Thanks in advance.
Description
You can use jQuery’s
.removeAttr(),attr(),.next()and.prev()methods for that.Check out my sample and this jsFiddle Demonstration
Sample
More Information
Update
I don’t know if you want to disable the, for example, next button if the last element is selected, select the first one or do nothing. Please provide this information.
You can do this to go to this to go to the first element if the last is selected, or to the last if first is selected.
Updated jsFiddle