I'd like to get the HTML of a DOM element that was dynamically created:
var titleTag = document.createElement("h4");
titleTag.innerHTML = 'this is a title';
How can I get the entire DOM element with tags?
<h4>this is a title</h4>
I'd like to get the HTML of a DOM element that was dynamically created:
var titleTag = document.createElement("h4");
titleTag.innerHTML = 'this is a title';
How can I get the entire DOM element with tags?
<h4>this is a title</h4>
The simple way is with outerHTML
. This has historically been frowned upon, because it was custom Internet Explorer functionality that was not in any standards, but it is now widely supported and even in a W3C draft standard.
var HTML = titleTag.outerHTML;
this is a title
`. Fiddle: https://jsfiddle.net/kc85ntwo/ – justDan Dec 05 '16 at 23:57