2017年7月1日 星期六

[JS]網頁學習 第五章 DOM Navigation, DOM Nodes 小節 心得小記

A common error in DOM processing is to expect an element node to contain text.

使用 childNodes[n].nodeValue 等同於使用innerHTML,
但若接在 getElementById 之後,Id 有唯一性,
又何必用 node 呢?還需要找出 elemnt 的序數。
----

Nodes creat 有個感覺是相當重要的範例:

<div id="div1">
<p id="p1">This is a paragraph.</p>
<p id="p2">This is another paragraph.</p>
</div>

<script>
var para = document.createElement("p");
var node = document.createTextNode("This is new.");
para.appendChild(node);

var element = document.getElementById("div1");
element.appendChild(para);

</script>


沒有留言:

張貼留言