I feel like this question has been asked before but the answers seem pretty specific to each poster.
I’m looking for a way to identify a given element and find the next element that has a particular class. I don’t want to have to deal with parent() or children() since I’m parsing through a table and I don’t want it to stop at the end of a row or even the end of the table itself (there are two side-by-side).
Is there any way to just search the entire page for the next instance of an element?
BACKGROUND INFO:
http://jsfiddle.net/HKkAa/2/
I’m trying to iterate through the bottom table starting at the highlighted cell and applying the “highlight” class to each cell until I reach the end date. I have a way to calculate when I’ve reached the end date, I just need the magic method to select the next instance of a link.
Edit
For anyone interested, I’ve plugin-ified this here: https://github.com/techfoobar/jquery-next-in-dom
There is no built-in way of doing this in jQuery if you want it to be completely generic and able to satisfy all/any DOM structure. I once worked out a simple recursive function that does this. It goes like:
And you can call it like:
For ex:
will get you the first matching
.fooafter$('#item')regardless of the DOM structureCheck the original answer here: https://stackoverflow.com/a/11560428/921204