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

149
Views
Parsing functions into dangerouslysetinnerhtml

I've currently go an issue with dangerouslysetinnerhtml. I'm trying to allow people to edit sections via a js document in react, and these edits appear in a form of a string. e.g. a person could parse the following as a string within the js file:

let html = `<div onClick="(input)=>{console.log(input)}">Click me</div>`

And in my code I'd like to display it as:

<div dangerouslySetInnerHTML={{ __html: html }}></div>;

The div appears just fine, but the 'onClick' function doesn't fire. I've seen recommendations to use HTML Parser, but that's not an option as I'm restricted from using external libraries in this case. Does anyone have any suggestions on how this should work?

Thanks!

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

0

You can do this way if you really need to.

let html = '<div onclick="console.log(this)">Click me</div>';

And same as you have done in your code.

<div dangerouslySetInnerHTML={{ __html: html }}></div>;
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!