Reputation: 404
Is there any way to target href in anchor tag through javascript? If not then what should I use?
This is the HTML:
<a href="*I want to inject here through javascript or Jquery">
Upvotes: 0
Views: 497
Reputation: 54
same as Divyesh but pure javascript:
var a = document.getElementById('link');
a.href = "www.newlink.com";
or chained if you don't need a reference to a
document.getElementById('link').href = "www.newlink.com";
Upvotes: 3
Reputation: 806
You can do it with javascript:
document.getElementById("link").setAttribute("href", "http://www.yourUrl.com");
Upvotes: 0
Reputation: 2740
You can do it using jquery as follow
<a id="link" href="*I want to inject here through javascript or Jquery">
And in jquery
$("#link").attr("href","www.newlink.com");
Upvotes: 2