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?