[英]Getting the entire HTML of a dynamically created element
我想獲取動態創建的DOM元素的HTML:
var titleTag = document.createElement("h4");
titleTag.innerHTML = 'this is a title';
如何獲得帶有標簽的整個DOM元素?
<h4>this is a title</h4>
簡單的方法是用outerHTML
。 歷史上一直對此表示反對,因為它不是任何標准中的自定義Internet Explorer功能,但現在得到了廣泛的支持,甚至在W3C草案標准中也得到了支持。
var HTML = titleTag.outerHTML;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.