In the same way that I can inject some text into a div with javascript, how can I inject a string into the href portion of an html anchor?
var div = document.getElementById('hrefId');
div.innerHTML = "Some dandy text!";
Something like this?
var hrefVar = document.getElementById('hrefId');
hrefVar.innerHTML = "Some dandy text!";
The problem is that it populates the space between <a></a>, as opposed to filling up the href with text, which is what I need to get the link to work.
<a href="" id="href"></a>
Solution:
var hrefVar = document.getElementById('hrefId');
hrefVar.href = "http://www.microsoft.com/";
document.getElementById('whatever').href="some text"orsetAttributeif you want to change the DOM and not just the element property$("#href").attr("href","Hello World");