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

301
Views
Import module for webpack to map <html onclick=""> dependency for JS generated elements

I'm generating and appending elements in JS with template literals. These elements need onclick listeners. Instead of selecting and setting in JS, I thought of putting the onclick in the template instead:

// report.js
export default function report() { console.log('Running') }
// template.js
export default elementHTML = `<div onclick="report()"></div>`
// draw.js
import elementHTML from './template.js'

export default function draw(){
  const container = document.getElementbyId('container')

  for (let i = 0; i < 20; i++) {
     const domElement = document.createElement('div')
     container.appendChild(domElement)
     domElement.outerHTML = elementHTML
  }
}
// index.js
import draw from './draw.js'

draw()

In which file should I import report so that webpack knows to import it as a module dependency for the html onclick to run?

about 4 years ago · Santiago Gelvez
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!