How to automatically scroll to a specific row in a table?

I have an html page with a header, a table containing 100 elements and a footer.

When there is a search, I highlight the line containing the data.

However, if the highlighted line is line 75, the user must scroll down to find it.

How can I automatically scroll this line?

I saw scrollTo () , but see that it only accepts axial points.

Any suggestions?

Thanks.

(Using cgi in C, html, css and javascript / jquery)

+6
javascript jquery dom html
source share
3 answers

You can use scrollIntoView() . (This is directly on the DOM elements.)

Keep in mind that there are some layout situations where scrolling something on a page can cause IE6 and 7 to decide that random other things need to be scrolled.

+9
source share

try the following:

  <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)">

+2
source share

I think you can do something like this:

Use this line anywhere

 <a id="bookmark"></a> 

and when you start your page, call it like this:

 http://mypage.com/setting.php#bookmark 

This worked for me without showing the anchor.

Check again to use bookmark in html

Editorial: Check: JavaScript - Go Anchor

0
source share

All Articles