Reputation: 33956
I'm using this script that takes an url and modifies it. It stores the new URL in a variable called #url and then it sets that variable as the href of a link.
It's changing the HREF however instead of printing the URL it's creating a link to the name of the variable: #url
This is the script:
if(url.match(/http:\/\//))
{
url = url.substring(7);
}
if(url.match(/^www\./))
{
url = url.substring(4);
}
url = "www.chusmix.com/tests/?ref=" + url;
$("#output").html(url);
$("#url").val(url).focus().select();
var yourElement = document.getElementById('test');
yourElement.setAttribute('href', '#url');
I'm trying to make it work in JSFiddle, I just tried chaning the quotes but didn't work.
http://jsfiddle.net/Lisandro/JKxRg/4/
Thanks for any help
Upvotes: 0
Views: 252
Reputation: 13723
yourElement.setAttribute('href', '#url');
'#url'?
You're printing a literal, so why are you surprised when you see a literal. jhanifen has given you the correct answer.
Upvotes: 0
Reputation: 4591
Remove the single quotes and no need to update the val if you going to change the attribute later.
yourElement.setAttribute('href', url);
Upvotes: 1