TIMEX
TIMEX

Reputation: 271774

How do I change the "href" of <a> through Javascript Jquery?

Suppose I have this:

<a id="main_link" href="http://feedproxy.google.com/~r/AmazonWire/~5/FN5UZlXKwdY/SalmanRushdiePodcast.mp3">

How do I use Jquery to change the "href" to something else?

Upvotes: 0

Views: 404

Answers (3)

nr404
nr404

Reputation: 46

$("#main_link").attr("href","http://...");

http://docs.jquery.com/Attributes/attr

Upvotes: 1

Jason
Jason

Reputation: 52523

$('#main_link').attr('href','your new href');

Upvotes: 0

Crescent Fresh
Crescent Fresh

Reputation: 116980

Get a reference to your link, and use the attr method on it:

$('#main_link').attr('href', 'something_else');

That grabs the elements with id="main_link" using the id "#" css selector (should only be one in the document), and sets the href attribute of all (again, should only be one in the document).

jQuery can perform the exact same operation on batch to a class of elements:

$('.main_link').attr('href', 'something_else');

That grabs the elements with css class="main_link" instead.

Upvotes: 6

Related Questions