[DOM]-6.innerHTML(上)

<div id="main"></div>
var el = document.getElementById('main');
var str = '<h1 class="blue">1234</h1>';
el.innerHTML = str+str;
.blue{
  color: blue;
}

1.如在html的id="main"文字加Hello使用innerHTML會清空
2.Element html標籤拉進去在裡面使用innerHTML
3.textContent是新增文字的節點

codepen

评论

此博客中的热门博文

JavaScript-頁數總結

六角學院-高雄資訊旅遊

JavaScript-巢狀迴圈內外if判斷字串與陣列