I need to be able to cycle through the next occurrence of a given text on a page. In the same way as the most common βfindβ function in almost every software (F3 - find further).
I'm trying to do this with jQuery, but I just can't get it to work. Tried: NextAll (), next (), closest () (which seems erroneous), find (), eq (), children (), etc. Etc. Etc.
Below is a sample that works, but it goes to the last element on the page and does not go in a circle.
function scrollMe(tow){ var targetOffset = $("*:contains('"+tow+"'):last").offset().top; $('html,body').animate({scrollTop: targetOffset}, 1000); }
To make it clear, on my page there is a set of lines (div) with text inside. Each time the user clicks on this line, he must carefully slide (or up) to the next line with the appearance of the text (if any).
Sample:
<div onclick="scrollMe('hello');">hello</div> <div onclick="scrollMe('world');">world</div> <div onclick="scrollMe('foo');">foo</div> <div onclick="scrollMe('hello');">hello</div> <div onclick="scrollMe('bar');">bar</div>
Indeed, it should be enclosed in jQuery, but this is for illustration only.
source share