JavaScript: The Definitive Guide, Sixth Editio javaScript权威指南(第6版) pdf 文字版-文字版, javascript电子书, 和javascript 有关的电子书:

15.6 Creating, Inserting, and Deleting Nodes

15.6 Creating, Inserting, and Deleting Nodes

We’ve seen how to query and alter document content using strings of HTML and of plain text. And we’ve also seen that we can traverse a Document to examine the individual Element and Text nodes that it is made of. It is also possible to alter a document at the level of individual nodes. The Document type defines methods for creating Element and Text objects, and the Node type defines methods for inserting, deleting, and replacing nodes in the tree. Example 13-4 demonstrated both node creation and node insertion, and that short example is duplicated here:

// Asynchronously load and execute a script from a specified URL

function loadasync(url) {

var head = document.getElementsByTagName("head")[0]; // Find document

var s = document.createElement("script"); // Create aelement

s.src = url; // Set its src attribute

head.appendChild(s); // Insert theinto head


The subsections that follow include more details and examples of node creation, of the insertion and deletion of nodes, and also of the use of DocumentFragment as a shortcut when working with multiple nodes.

友情链接It题库(| 版权归yishouce.com所有| 友链等可联系|粤ICP备16001685号-1