标签:
// HTML: // <div id="container"><div id="d">This is a div.</div></div> container = document.getElementById("container"); d = document.getElementById("d"); console.log(container.firstChild.nodeName); // logs "DIV" d.outerHTML = "<p>This paragraph replaced the original div.</p>"; console.log(container.firstChild.nodeName); // logs "P" // The #d div is no longer part of the document tree, // the new paragraph replaced it.
While the element will be replaced in the document, the variable whose outerHTML
property was set will still hold a reference to the original element!
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | 4 | 45 (45) | 6 | 9.6 (probably earlier) | 3 |
t[t.innerText ? ‘innerText‘ : ‘textContent‘] = v.n
it = currHeaderChildNodes[i].innerText || currHeaderChildNodes[i].textContent;
innerHTML/outerHTML; innerText/outerText; textContent
标签:
原文地址:http://www.cnblogs.com/gentlemint/p/5484808.html