Elements added via HTML string disable onclicks/event listeners of previous elements
Fiddle: https://jsfiddle.net/eptcrwfd/37/
The solution is putting onclick declarations in a setTimeout on a minimal time like that
setTimeout(() => {
document.getElementById("element-id").onclick = () => {
console.log(1)
}
})
but it doesn’t seem like the best way and i still want to know what causes this behavior in the first place
New contributor
mintBunHunter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1