PDA

View Full Version : change a link



lord22
11-16-2009, 02:21 PM
Hi,

I have a simple link:


<a href="#" id="my">text</a>

and I want to change the href value (#) into another with an external js function, how can I do it?

Thanks! :)

Schmoopy
11-16-2009, 02:30 PM
function changeLink(id,link) {
document.getElementById(id).href = link;
}

changeLink('my','changed.html');


I'm terrible with JavaScript, but I think the above may work, can't test it for you at the moment though, unfortunately.