// create the element var newLink = document.createElement("a"); // add the URL attribute newLink.setAttribute("href", "http://www.w3.org/DOM/"); // Add some text newText = document.createTextNode("What is DOM?"); // Add it to the new hyperlink newLink.appendChild(newText); // Find the place to put it placeholder = document.getElementById("myLink"); // add this to the DOM in memory placeholder.appendChild(newLink);
Comment
// create the element
var newLink = document.createElement("a");
// add the URL attribute
newLink.setAttribute("href", "http://www.w3.org/DOM/");
// Add some text
newText = document.createTextNode("What is DOM?");
// Add it to the new hyperlink
newLink.appendChild(newText);
// Find the place to put it
placeholder = document.getElementById("myLink");
// add this to the DOM in memory
placeholder.appendChild(newLink);