When I add HTML to a div element and later try to get it back, jQuery either removes the HTML tags or converts all applicable characters to HTML entities, depending on if I use .html() or .text().
Here's a demonstration (jsfiddle)
$('div').html('<h1>Hi, Alice & Bob</h1>');
console.log('html: ' + $('div').html());
console.log('text: ' + $('div').text());
Console output
html: <h1>Hi, Alice & Bob</h1>
text: Hi, Alice & Bob
How do I get back exactly <h1>Hi, Alice & Bob</h1>?
innerHTML?.html()is based oninnerHTML. I have, however, updated the jsfiddle to demonstrateinnerHTML.