Skip to content

Instantly share code, notes, and snippets.

@foru17
Last active August 29, 2015 14:02
Show Gist options
  • Save foru17/2711eed237778379793f to your computer and use it in GitHub Desktop.
Save foru17/2711eed237778379793f to your computer and use it in GitHub Desktop.
js创建和添加元素
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