Reputation: 688
I am trying to change the attribute of an <a>
tag using jQuery but it's not working. I am trying to change the src
attribute of the <a>
tag from www.google.com
to www.somewebsite.com
. Can anyone please tell me where I am getting it wrong.
<p class="form-row text-varient">
<label class="checkbox">
Some text here
<a target="_blank" href="http://google.com">Link Text</a>
</label>
</p>
jQuery(document).ready(function(){
jQuery(".text-varient").find("a").attr("href", "http://www.somewebsite.com/");
});
Upvotes: 0
Views: 97
Reputation: 7256
jQuery(document).ready(function(){
$(".checkbox").find('a').attr("href", 'http://www.somewebsite.com');
});
Upvotes: 2
Reputation: 1
Try this:
<p class="form-row text-varient">
<label class="checkbox">
Some text here
<a target="_blank" href="http://google.com">Link Text</a>
</label>
</p>
<script>
$(document).ready(function(){
$(".checkbox a").attr("href", "http://www.somewebsite.com");
});
</script>
Upvotes: 2