Possible Duplicate:
How to change the href for a hyperlink using jQuery
I have a link that is being generated by a database that I need to change.
I was wondering if I can use jQuery to find the required id and change the href value?
Possible Duplicate:
How to change the href for a hyperlink using jQuery
I have a link that is being generated by a database that I need to change.
I was wondering if I can use jQuery to find the required id and change the href value?
If your HTML was like this:
<a href="xxx" id="myLink">whatever</a>
You can change the link by doing this in plain javascript:
document.getElementById("myLink").href = "http://whatever.com/yyyy";
Or, using jQuery:
$("#myLink").attr("href", "http://whatever.com/yyyy");
Yes.
<script>
$(function() {
$("#id_of_link").attr("href", "/new/url");
});
</script>
If you want to do this when the page loads, use the following code
$(document).ready(function() {
$("#linkId").attr("href", "http://the.new.url");
});