Ali
Ali

Reputation: 267049

How to scroll to a particular <li>?

How can I send a user to a url where it will automatically scroll to a given <li>?

E.g mysite.com/something.html#someItem

have him scroll to

<ul>
   <li id='someItem'>Something here</li>
</ul>

Upvotes: 2

Views: 433

Answers (3)

Ben
Ben

Reputation: 10104

You need an anchor tag. Like this:

<ul>
   <li id='someItem'>
       <a name='someItem'></a>
       Something here
   </li>
</ul>

Edit: markup

Upvotes: 0

Peter-Paul van Gemerden
Peter-Paul van Gemerden

Reputation: 7011

There's plenty of examples of scrolling to (any) element using jQuery. There's even plugins that'll do it for you, like ScrollTo. :-)

If you want a (really) simple example, here it is:

function scrollTo(selector) {
    $('html, body').stop().animate({
        scrollTop: $(selector).offset().top
    }, 1000,'easeInOut');
}

Upvotes: 1

SLaks
SLaks

Reputation: 887275

Exactly that.
Your code will work as-is.

Upvotes: 8

Related Questions