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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.