How can I add “href” attribute to a link dynamically using JavaScript?

var a = document.getElementById('yourlinkId'); //or grab it by tagname etc
a.href = "https://stackoverflow.com/questions/4689344/somelink url"

Leave a Comment