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

332
Views
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
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!