Reputation: 1351
I am very new to JS and a Swift developer. I have a button that has this property:
<a href="http://phonefiveme.com/nocontact" id="yui_3_17_2_1_1490136681073_127" style="cursor: url("chrome-extension://ledmjlnkdlappilhaaihfhanlpdjjalm/rockhand.png"), auto;">
What I need to do is to edit that href to be a link that is stored in a variable. Here is what I have:
var currentLocation = window.location;
var stringURL = String(currentLocation);
var shortened = stringURL.substring(32);
var myElement = document.getElementById("yui_3_17_2_1_1490136681073_127");
I just need to replace "http://phonefiveme.com/nocontact" with shortened
Any help would be much appreciated! Thanks so much. Cheers, Theo
Upvotes: 1
Views: 917
Reputation: 26
you can access the properties of the html element and simply use
myElement.href=shortened;
to do the trick
Upvotes: 1
Reputation: 118
You can do this using the href JavaScript property.
Simply add to your JavaScript:
myElement.href = shortened;
See similar question for more reference.
Upvotes: 3
Reputation: 2366
Simple:
var currentLocation = window.location;
var stringURL = String(currentLocation);
var shortened = stringURL.substring(32);
var myElement = document.getElementById("yui_3_17_2_1_1490136681073_127");
myElement.href = myElement.href.replace("http://phonefiveme.com/nocontact", shortened);
Upvotes: 1