How to create an <a> element by using the document.createElement() method in JavaScript

1 Answer

0 votes
var link = document.createElement("A");
var linkText = document.createTextNode("Programming Q&A");
link.setAttribute("href", "http://www.collectivesolver.com/");
link.appendChild(linkText);
document.body.appendChild(link);

/*

run:

<a href="http://www.collectivesolver.com/">Programming Q&A</a>

*/

 



answered Apr 12, 2017 by avibootz
...