Javascript DOM - Create Element


/ Published in: JavaScript
Save to your folder(s)

Basic create element and append it too another element.


Copy this code and paste it in your HTML
  1. var root = document.getElementById("root");
  2.  
  3. var a = document.createElement("a");
  4. a.setAttribute("href", "http://foobar.com");
  5. a.setAttribute("title", "Foo Bar");
  6.  
  7. root.appendChild(a);

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.