When using jquery's next() function to get the next element in a list, how do I get the first element after reaching the end of the list? -


Technically, this is not for 'list' (ul-& gt; li), but for a series of

> div inside the container div . I have tried many different ways to try and achieve it, but none of them works; what happens when I go to the last element, and then click on my 'next button' , Then takes me to the second element in the list, never the first element. Generally, I'm using this code:

  & lt; Div class = "wrapperclass" & gt; & Lt; Div class = "myClass" id = "ID1" & gt; & Lt; Div class = "other class" & gt; & Lt; Input value = "myValue1" /> & Lt; / Div & gt; & Lt; / Div & gt; & Lt; Div class = "myClass" id = "ID2" & gt; & Lt; Div class = "other class" & gt; & Lt; Input value = "myValue2" /> & Lt; / Div & gt; & Lt; / Div & gt; & Lt; Div class = "myClass" id = "ID3" & gt; & Lt; Div class = "other class" & gt; & Lt; Input value = "myValue3" /> gt; & Lt; / Div & gt; & Lt; / Div & gt; ... & lt; / Div & gt;   

and

  var nextID = $ ('div #' + id) .next (). ('Input'). Val (); Var lastID = $ ('div #' + id + ': last'). ('Input'). Val (); If (nextID == lastID) {nextID = $ ('. WrapperClass') ('Input: first'). Val ();} // Other code    

I realize my mistake. I should have written <

  if (currentID == lastID) {// blah}   

writing this was also wrong for me < Pre $ '(' div # '+ id +': last ')

Since the ID should be unique. Thank you 'undefined' (the anonymous person I told.) I am clearly a newbie.

Comments