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.