I need to update href value thorughout the page using jquery. Say href=\"http://www.google.com?gsec=account\" should be changed to href=\"http://account.google.com?gsec=acco
This will do the replace throughout the page that I think you're looking for.
// Find `` elements that contain `www.google.com` in the `href`.
$('a[href*="www.google.com"]').attr('href', function(i,href) {
// return a version of the href that replaces "www." with "accounts."
return href.replace('www.', 'accounts.');
});
Try it out: http://jsfiddle.net/dT8j6/
EDIT: This version allows for https://
and for links without the www.
.
Try it out: http://jsfiddle.net/dT8j6/1/
$('a[href*="google.com"]').attr('href', function(i,href) {
return href.replace(/^http(s*):\/\/(www\.)*google.com/, 'http$1://accounts.google.com');
});
EDIT: If you only wanted to change elements that have gsec=account
, then change the selector to $('a[href*="gsec=account"]')
.