Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

237
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda