update all the href value in a page using jquery. I have the href="http://www.google.com" coming through out the page and i wanted to update the href mentioning above to be changed to "http://www.test.com" how i can get this done.
+1
A:
$('[href]').each(function () {
$(this).attr('href', 'http://www.test.com');
});
Codler
2010-08-10 13:13:32
+1
A:
$('a[href*="google"]').attr('href', 'http://www.test.com');
The selector will go through all links that have google somewhere in their href attribute with *= and if so, it will update their attribute accordingly.
Sarfraz
2010-08-10 13:13:48
This is what i wanted.
Patrick
2010-08-10 13:21:53
A:
Save this as an .html file for a complete working example!
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("a[href*='http://www.google.com']").attr('href','http://www.test.com').html('Test.com');
});
</script>
</head>
<body>
<a href="http://www.google.com">Google</a>
<a href="http://www.google.com">Google</a>
<a href="http://www.google.com">Google</a>
<a href="http://www.NotGoogle.com">Not Google</a>
</body>
</html>
Brandon Boone
2010-08-10 13:15:16
A:
use selectors
<script type="text/javascript">
$("a[href*='http://www.google.com']").attr('href','http://www.test.com');
</script>
clumsyfingers
2010-08-10 13:16:11