Cheatography
https://cheatography.com
Enhancing the DOM with JavaScript Lynda
Creating and appending nodesdocument.createElement(element) Makes a new element | Has to be added to the DOM | node.appendChild(element) Adds element inside a node |
Controlling node insertionsappendChild() lacks precision | Need to insert a node anywhere in the node list | Use insertBefore() for surgical insertions | newNode.insertBefore(pNode, newNode.childNodes[5]) |
| | Cloning and removing nodescloneNode() makes a copy | you can then reposition the node | removeChild(node) removes the node | Has to be called from a parent node | var newNode = myNode.cloneNode(true) copy node and all its children | insertLocation.insertBefore(newNode, insertLoction,childNodes[4]) | myNode.parentNode.removeChild(myNode) |
Replacing existing nodesreplaceChild() replaces a node | You must call it from the parent node | Saves you the step of having to delete the original | replaceNode.parentNode.replaceChild(myNode, replaceNode) |
|
Created By
Metadata
Favourited By
Comments
No comments yet. Add yours below!
Add a Comment
More Cheat Sheets by [deleted]