Reputation: 47
I am learning the basics on jQuery and feel this should work based on what I've learned so far. Why doesn't the href get updated with the button click event?
Thanks
(The jQuery .js is loaded in the header correctly)
<div>
<input id = "ChangeLink" type="submit" value="Change Link"/>
</div>
<div class="divClass">
<ul id="defaultList">
<li><a id="link1" href="#">Item 0</a></li>
</ul>
</div>
<script type="text/javascript">
$(document).ready(function() {
$("#changeLink").click(function() {
$("#link1").attr('href', 'http://www.google.com');
});
});
</script>
Upvotes: 0
Views: 327
Reputation: 33218
You have wrong id, is $("#ChangeLink").click(function()
with capital -C-:
$("#ChangeLink").click(function() {
$("#link1").attr('href', 'http://www.google.com');
return false;
});
Upvotes: 3
Reputation: 754
Your jQuery selector says #changeLink
but your the id of your element is ChangeLink
(with a capital). Make them both the same.
Upvotes: 4