// Option 1 // set the content using .innerHTML() // and add the classes manually to the classList elem.innerHTML = "This is the comment"; elem.classList.add('comment'); // Option 2 // set the content and classes in one go using .outerHTML() elem.outerHTML = "<article class=...
<title> 也没有innerHTML属性。 outerHTML 与 innerHTML 的不同点: 在读模式下,outerHTML 返回调用它的元素及全部子节点的HTML 标签。 在写模式下,outerHTML 会依据指定的HTML 字符串创建新的DOM 子树。然后用这个DOM子树全然替换调用元素。(而不不过调用元素的DOM子树)...
<button onclick="showInnerText()">innerText</button> <button onclick="showOuterText()">outerText</button> </div> var showInnerHTML = function(){ console.log(document.getElementById("outer").innerHTML); } var showOuterHTML = function(){ console.log(document.getElementById("outer").outerH...
innerText结果:测试 outerText结果:测试 3、简单说一下innerHTML、outerHTML、innerText和outerText的不同之处: 1)、innerHTML与outerHTML在设置对象的内容时包含的HTML会被解析,而innerText与outerText则不会。 2)、在设置时,innerHTML与innerText仅设置标签内的文本,而outerHTML与outerText设置包括标签在内的文本。 特别...
innerText和outerText在获取的时候是相同效果,但在设置时,innerText仅设置标签所包含的文本,而outerText设置包含包括标签自身在内的文本。 例子1:outerHTML和innerHTML的区别 document.body.outerHTML: !DOCTYPE html> html> head> /head> body> div>aa/div> ...
<!DOCTYPE html> <html> <head> </head> <body> <div>aa</div> <script type="text/javascript"> alert(document.body.innerHTML); </script> </body> </html> 结果: 通过不同的结果可以得出:outerHTML属性比innerHTML属性多包含了<body>标签 还有需要注意的是:innerHTML是所有浏览器都支持的属性。out...
innerHTML, innerText, outerHTML, outerText的区别 firefox并不支持,但chrome支持。innerHTML和innerText的区别:innerHTML会对获取到的内容做解析,将标签进行解释。 innerText会将读取到的一切视作文本(包括...结论innerHTML返回标签内部嵌套的子元素的所有(HTML标签+ 文本内容content)。 innerText 返回标签内部嵌套的子元...
2.outerHTML 属性 3.insertAdjacentHTML 方法 innerHTML 属性 有两种模式。写模式与读模式。 在读模式下,返回的是html 代码字符串。 比如: <divid="outer"><p>This is a<strong>paragraph</strong>with a list following it.</p><ul><li>Item 1</li><li>Item 2</li><li>Item 3</li></ul></div...
<a href="javascript:alert(test.innerText)">inerHTML内容</a> <a href="javascript:alert(test.outerHTML)">outerHTML内容</a> 特别说明: innerHTML是符合W3C标准的属性,⽽innerText只适⽤于IE浏览器,因此,尽可能地去使⽤innerHTML,⽽少⽤innerText,如果要输出不含HTML标签的内容,可以使⽤...
alert(document.getElement("d").innerTEXT); 显示: aaa dadsa 其中,outerHTML,IE支持,测试FF不支持。 可以获得包括自身的全部html标签和内容。 上例中: alert(document.getElement("d").outerHTML); 显示: <div id="d"> aaa <div>dadsa</div> </div>...