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

249
Views
React JS scrollLeft does not work with class name selector

I have container with horizontal scrolling. When I click a button I want to scroll to the end of the container (all the way to the right).

My on click function:

const scrollToEnd = () => {
  var parent = document.getElementsByClassName('custom-class-name');
  for(var i=0;i<parent.length;i++) {
    var child = parent[i].getElementsByClassName('my-container');
    child[0].scrollLeft = 100;
  }
}

In my return function

<Button
  onClick={(e) => {
    anotherFunction();
    scrollToEnd();
  }}
/>

Nothing happens when I click the button. I tested to see if I am selecting the right element using a style:

child[0].style.color='red';

This works. Style color red is added to .my-container but scrollLeft does not work.

about 4 years ago · Juan Pablo Isaza
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!