Reputation: 862
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>
Upvotes: 2
Views: 48
Reputation: 237865
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;
Upvotes: 2