Find out if Next item is equal to last item?
I have some js code in which a click on a nav arrow causes list to be walked up or down and hilighted. Partial code is below. The problem is that when I get to the end of the list (e.g. there IS no next()), I want to skip this part of the code and actually hide the right arrow. I have no problem with the hiding part - I just want to set a flag when I have traversed the list to the last item.
**Actually, I just need to find if the next item is equal to the last item in the list and set a flag.
Here's the code for highlighting the next list item:
- $("#sub_menu .on").removeClass("on").addClass("off").parent("li").next().children("a").addClass("on").click();
I tried something like this:
- val1 = $("#sub_menu").parent("li").last();
- val2 = $("#sub_menu").parent("li").next();
- if val1 == val2 {
- var lastItem = true;
- $("#arrow_right").css({visibility:"hidden"});
- }