Reputation: 1024
I want to change an anchor link on a certain page using jQuery.
How can I change the anchors link to something like #
or javascript:void(0)
?
Upvotes: 0
Views: 1319
Reputation: 79850
To change one link,
<a href="http://www.google.com" id="link">One Link</a>
$('#link')[0].href = '#';
Plain javascript:
document.getElementById('link').href = '#'
Changing multiple links,
<a href="http://www.google.com" class="links">One Link</a>
<a href="http://www.yahoo.com" class="links">One Link</a>
<a href="http://www.hotmail.com" class="links">One Link</a>
$('a.links').each(function () {
this.href = '#';
});
Upvotes: 3
Reputation: 145458
<!-- HTML -->
<a href="http://stackoverflow.com/" class="mylink">Link</a>
// JavaScript
$("a.mylink").prop("href", "#");
Upvotes: 1