Your solution proposal (use the next
and the addClass
) is correct. Here’s a simple example (no limit conditions check - like the first or last element):
$(".selecionado")
.removeClass("selecionado")
.next()
.addClass("selecionado");
Example in jsFiddle.
P.S. A solution (not necessarily the most "clean") to test the boundary cases would be to check at the end of the code if "there is" someone selected and, if not, to choose one as a pattern (the latter, if you want him to "stop moving forward", or the former, if you want him to "turn around"). Examples:
if ( $(".selecionado").length == 0 )
$("li:last").addClass("selecionado");
Stopping example, example going around.
Looks like the way is right there... could post the code you used to try, maybe it’s just a silly detail...
– mgibsonbr
You can edit this fiddle to show your problem better? : http://jsfiddle.net/zNVG6/
– Sergio
Dude, sorry, I don’t have the code anymore, since I couldn’t, I got pissed and I deleted :(
– Odair