Try something like:
$(function(){
$(".selectoption").data("index",1).find("li:not(:first)").hide();
$(".previous").click(function(){
$(".selectoption").data(
"index",
$(".selectoption").data("index") - 1
);
$(".selectoption li").hide().eq($(".selectoption").data("index")).show();
return false;
});
$(".next").click(function(){
$(".selectoption").data(
"index",
$(".selectoption").data("index") + 1
);
$(".selectoption li").hide().eq($(".selectoption").data("index")).show();
return false;
})
});
With a data object in jQuery, you can associate any javascript data with a dom element. I used this to keep the list state.
You might want to add security features for the first and last items in the next / previous steps.
source
share