0

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?

1
  • Holy, just discovered this was actually a dupe of stackoverflow.com/questions/179713/… alex, how did you not see that previously asked question when you posted this? Commented Nov 22, 2009 at 4:24

3 Answers 3

6

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

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

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.