1

Create and Add Nodes

  • Create Nodes

  • We can create two kind of element

    • Create a Element document.createElement('h1');
      • The simple fact to create a node is not mean that we add this new node into DOM, the element is save on memory.
    • Create Text document.createTextNode('text');
  • Add Nodes

    • parentElement.appendChild('referentNode, newNode')
      • Always add a new node at end
    • parentElement.append() doesn’t work on Internet Explorer
    • parentElement.insertBefore('referentNode', newNode)
      • referent node have to be a child of the base node
    • parentElement.insertAdjacentElement('positionNode','newNode')
    • String ways | Have securities problems
      • node.outerHTML(read)
      • node.innerHTML(write)
Escribe tu comentario
+ 2