Ladan Posted December 1, 2020 Report Share Posted December 1, 2020 Hi all. I've been long looking into a solution to my jQuery/JS code, but to no avail. I want to be able to scroll to the searched term when I type it in. It will do this now, but then if I search for a word that's at the top, I don't have anything for it to scroll up to it. Here is my code: $(function() { $('.searchTerm').bind('keyup change', function(ev) { // pull in the new value var searchTerm = $(this).val(); // remove any old highlighted terms $('body').removeHighlight(); // disable highlighting if empty if ( searchTerm ) { // highlight the new term $('body').highlight( searchTerm ); $('html, body').delay(1500).animate({ scrollTop: $('#results').offset().top }, 475); } }); }); Is there something missing, or am I using the wrong code? I don't know what to do. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.