I try to get the outer HTML in two different ways, based on this question. Unfortunately, none of them is giving the expected result:
HTML:
<div id='my_div'>Hello</div>
JS:
$(function() {
document.write('[' + $('#my_div').clone().wrapAll("<div />").parent().get(0).innerHTML + ']<br />');
document.write('[' + (new XMLSerializer().serializeToString(document.getElementById('my_div'))) + ']');
});
The output is:
[
Hello
]
[
Hello
]
I expect the following result: <div id='my_div'>Hello</div>
What am I doing wrong ?