I have an html page with a header, a table containing 100 items and a footer.
When there is a search, I highlight the row containing the data.
However, if the highlighted row is row 75, the user has to scroll down to find it.
How can I automatically scroll to that row?
I did see scrollTo() but see it only takes axis points.
Any suggestions?
Thanks.
(Using cgi in C, html, css and javascript/jquery)
I have an html page with a header, a table containing 100 items and a footer.
When there is a search, I highlight the row containing the data.
However, if the highlighted row is row 75, the user has to scroll down to find it.
How can I automatically scroll to that row?
I did see scrollTo() but see it only takes axis points.
Any suggestions?
Thanks.
(Using cgi in C, html, css and javascript/jquery)
Share Improve this question edited Nov 21, 2011 at 13:44 nikow 21.6k7 gold badges53 silver badges71 bronze badges asked Sep 23, 2010 at 18:03 T.T.T.T.T.T. 34.6k47 gold badges134 silver badges172 bronze badges3 Answers
Reset to default 9You should be able to use scrollIntoView()
. (It's on the DOM elements directly.)
Be aware that there are some layout situations where scrolling something on the page can cause IE6 and 7 to decide that random other stuff needs to be scrolled too.
try this:
<script> function ScrollToElement(theElement){ var selectedPosX = 0; var selectedPosY = 0; while(theElement != null){ selectedPosX += theElement.offsetLeft; selectedPosY += theElement.offsetTop; theElement = theElement.offsetParent; } window.scrollTo(selectedPosX,selectedPosY); } </script> <body onload="ScrollToElement(document.formName.elementName)">
I think you can do something like this:
Use this line where ever you like,
<a id="bookmark"></a>
and when you start your page, call it like this:
http://mypage./setting.php#bookmark
That worked for me without showing the anchor.
Check again for using bookmark in html
EDITED: Check: JavaScript - Jump to anchor