JSFiddle - React, Tailwind, and code Playground
HTML
<div id="test"><span id="abc">click</span>some content</div>
JavaScript
var str = '<p>Just some <span>text</span> here</p>';
document.getElementById('abc').onclick = function() {
alert('Hello from `onclick`');
};
document.getElementById('abc').addEventListener('click', function() {
alert('Hello from `addEventListener`');
}, false);
// Naive way
document.getElementById('test').innerHTML += str
return;
// My way
var child = document.createElement('div');
child.innerHTML = str;
child = child.firstChild;
document.getElementById('test').appendChild(child);