JavaScript 之 innerHTML和outerHTML

innerHTML是指对象内所包含的HTML代码

outerHTM是指对象本身和对象内所包含的代码

一般的HTML元素都可以使用,当然如果当前元素并没有包含HTML的话返回的是0长度字符串了

 

Code
<html>
<body>
    
<div id="aa">
        
<span style="color: red;">This is a span in a div!</span></div>
    
<button onclick="alert(aa.innerHTML);">
        innerHTML
</button>
    <button onclick="alert(aa.outerHTML);">
            outerHTML
</button>
</body>
</html>

 

你可能感兴趣的:(JavaScript 之 innerHTML和outerHTML)