user1658756
user1658756

Reputation: 1024

Change Anchor Link Using jQuery

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

Answers (2)

Selvakumar Arumugam
Selvakumar Arumugam

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

VisioN
VisioN

Reputation: 145458

<!-- HTML -->
<a href="http://stackoverflow.com/" class="mylink">Link</a>

// JavaScript
$("a.mylink").prop("href", "#");

Upvotes: 1

Related Questions