How to find next and previous “A” element from “#current” using jQuery.
HTML:
<ul>
<li>
<a></a>
<a></a>
<a></a>
</li>
<li>
<a></a>
<a></a>
<a id='current'></a>
</li>
<li>
<a></a>
<a></a>
<a></a>
</li>
</ul>
i’ve tried to create a code with something like this:
var curr = $('#current');
var prev = curr.parent().prev('a');
var next = curr.parent().next('a');
But it didn’t work. I think it’s a very easy questions, but i’m stuck right now. Any ideas?
UPD: It should travel to next “LI” element to find “A” if it’s the last “A” element in current “LI”.
You do not need to use parent to get prev and next
Live Demo
To make this cross row you need to check if you have current element first or last of row. If current element is first then last would be last element for previous row and similarly if current element is last of row then next will be first of next row.
Live Demo