Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

97
Views
Jump to right side of html page

I have an HTML page with a big table and many columns, I need to scroll right of page automatically on page load.

I've tried this code but it doesn't work for me :

</script><script type="text/javascript">  
                               
   var myDiv = document.getElementById('containerDiv');
   myDiv.innerHTML = variableLongText;
   myDiv.scrollRight = 0;

</script>

Is it a correct approch to auto scroll the page?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You can try this code.

<script type="text/javascript">  
                           
  var myDiv = document.getElementById('containerDiv');

  myDiv.scrollTo(0, myDiv.scrollRight)

</script>
about 4 years ago · Juan Pablo Isaza Report

0

Try like this:

// Getting div from DOM
const myDiv = document.getElementById('containerDiv');

// Getting div's position 
divRect = myDiv.getBoundingClientRect();

// Scrolling to div's position
window.scrollTo({
  top: divRect.top,
  left: divRect.left,
  // behavior: 'smooth'
});

/* 
behavior: 'smooth' will give a smooth sensation with a slow transition on scroll. 
I would personally recommend using it (mainly if this is not intended to run on load).
*/

Better & without comments:

const divRect = document.getElementById('containerDiv').getBoundingClientRect();
window.scrollTo({ top: divRect.top, left: divRect.left });

For information about getBoundingClientRect(), check this article https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect

about 4 years ago · Juan Pablo Isaza Report

0

if you want to scroll window then use

window.scrollTo(x-axis,y-axis);

or for specific div use

document.getElementById('container').scrollLeft += 10000;

so full program be like

window.onload = function() {
 // for specific div
  document.getElementById('nan').scrollLeft += 100000;
 
 //for window 
 /* window.scrollTo(10000, 0) */;
};

you can also see example https://jsfiddle.net/zcmhp2de/38/

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!