InnerHTML clear all data like event for existing nodes
append child with firstChild adds only first child to innerHTML. For example if we have to append:
<p>text1</p><p>text2</p>
only text1 will show up
What about this:
adds special tag to innerHTML by append child and then edit outerHTML by deleting tag we've created. Don't know how smart it is but it works for me or you might change outerHTML to innerHTML so it doesn't have to use function replace
function append(element, str)_x000D_
{_x000D_
_x000D_
var child = document.createElement('someshittyuniquetag');_x000D_
_x000D_
child.innerHTML = str;_x000D_
_x000D_
element.appendChild(child);_x000D_
_x000D_
child.outerHTML = child.outerHTML.replace(/<\/?someshittyuniquetag>/, '');_x000D_
_x000D_
// or Even child.outerHTML = child.innerHTML_x000D_
_x000D_
_x000D_
_x000D_
}
_x000D_
<div id="testit">_x000D_
This text is inside the div_x000D_
<button onclick="append(document.getElementById('testit'), '<button>dadasasdas</button>')">To div</button>_x000D_
<button onclick="append(this, 'some text')">to this</button>_x000D_
</div>
_x000D_