Jump to content
Killersites Forums

scroll up and down to find search terms


Recommended Posts

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

        // 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.

Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...