View Full Version : Scroll to LI element

02-16-2009, 05:48 PM
Hello Everyone,
I am using an UL to list files and directories for a file manager. Each LI item corresponds to either a file or directory. When the user clicks on a list item, the proper backend data is processed, and the class of the list item is changed to "highlighted", highlighting the item allowing the user to know which file is being modified.
The UL itself is placed in a DIV, and allowed to overflow, allowing the UL to be scrollable within a defined space. Everything works perfect, except, when a filename is clicked the page is refreshed, causing the UL to scroll back to the top. The correct item is highlighted, but if it falls below the viewable area, and needs to be scrolled to, it appears as though no file is selected.

In short, is it possible on page reload, to scroll to the specific LI item which has just been clicked? It would have its own unique ID and Class. I would like the "highlighted" item to have focus in the scrollable UL.

I hope this makes sense, Thank you for any assistance!

02-17-2009, 10:53 AM
It will help if you give us your code or better still, a link. It is very difficult to get to the problem without seeing what you have already done.
Use the # , above in the header, to enclose any code.


02-17-2009, 11:06 AM

Here is one method, which is basically a link which has the # mark in the URL to automatically go to an id.

Also with smooth scrolling and JS

http://www.sitepoint.com/article/scroll-smoothly-javascript/ (many more online)