Last active
August 29, 2015 14:02
-
-
Save foru17/2711eed237778379793f to your computer and use it in GitHub Desktop.
js创建和添加元素
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
theParent = document.getElementById("theParent"); | |
theKid = document.createElement("div"); | |
theKid.innerHTML = 'Are we there yet?'; | |
// append theKid to the end of theParent | |
theParent.appendChild(theKid); | |
// prepend theKid to the beginning of theParent | |
theParent.insertBefore(theKid, theParent.firstChild); | |
// appendChild() 方法在节点的子节点列表末添加新的子节点。 | |
// insertBefore() 方法在节点的子节点列表任意位置插入新的节点。 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment