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

264
Views
Detect click from an html element outside a React app and a react component

I have an html page with:

  • html elements
  • some empty divs that will be replaced with react elements.

I would like to listen to a "click event" of an html element from a react component.

Here, i need to get inside the "react-component" an event that will be triggered when we click on the "click" element.

<div id="click">button in static html</div>
<div id="react-component"></div> -> replace by a react component

Is there a way to achieve that? Thanks

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

0

onClick event handler on any html tag will work in react

about 4 years ago · Juan Pablo Isaza Report

0

You can still write normal JS code in react. Just add a useEffect(..., []) hook and bind your buttons onClick using standard JS code in there.

Here is the documentation for the JS onclick event: https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onclick

about 4 years ago · Juan Pablo Isaza Report

0

A few methods for this.
One of which is using querySelector or getElementById like you would in vanilla JS.

So you can do this:

// HTML:
<div id="click">button in static html</div>
<div id="react-component"></div> -> replace by a react component

// JSX:
const myElement = document.getElementById("click");
myElement.onclick = () => {
  ...
};
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!