Naco
Naco

Reputation: 862

Getting the entire HTML of a dynamically created element

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

Answers (1)

lonesomeday
lonesomeday

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

Related Questions