JS DOM: Create Element, Clone

By Xah Lee. Date: . Last updated: .
document.createElement(tagName)

Create a new tagName element. Return it.

γ€”see Create and Insert HTML Element〕

document.createTextNode(str)

Create a new text node with the node value of string str.

node.cloneNode(includeChildNodes)
  • Return a copy of node.
  • If includeChildNodes is true, include all child nodes.
  • Default to false.

πŸ›‘ WARNING: the cloned node have the same ID attribute, if the original has an ID. You should change it after cloning.

node.innerHTML

Basic DOM Element Methods