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

333
Vistas
reactjs Can't get the ID by using querySelector - ID value is generated from data reactjs

I trying to get the specified ID of the div when on click by using querySelector to query the ID that I want, it showing error below:

SyntaxError: Failed to execute 'querySelector' on 'Document': '#3dCubeSlider' is not a valid selector.

Here is the simplified codes

const Gallery = () => {

// some code that handling data from database

function handleShowGifDemo(e) {
  var parent = e.currentTarget.parentNode.id; // the id will be "3Dslider"
  var staticImg = document.querySelector("#" + parent); // This return the Error message
}
return (
<div className="content-bottom">
 <div className="grid-layout row"> 

  {gallery.map((value, key) => {
     return (
       <div id={value.tempid} className={value.tempid +" " +filtercategory +" col-xs-12 col-sm-6 col-md-3 text-center mb-5 align-items-stretch flex-column align-items-stretch gallery-box"} name="data_container" key={key}>
          <div className="demo-gif"></div>
          <div className="show-gif" onClick={handleShowGifDemo}>
              <i className="far fa-play-circle"></i>
          </div>
   </div>
</div>
)}

}

Wondering how to get the dynamic ID name when onClick?

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