<div class="content"><p>...link to <a href="http://www.google.com/">Google</a>in the content...</p><p>...second link to <a href="http://www.google.com/"id="changeme">Google</a>in the content...</p></div>
<div class="footer">Links: <a href="http://www.google.com/">Google</a></div>
$("a#changeme").attr('href','http://maps.google.com/');
var anchors = document.querySelectorAll('a');Array.prototype.forEach.call(anchors, function (element, index) {element.href = "http://stackoverflow.com";});
If you want to change the href value of all <a> elements that actually have an href attribute, select them by adding the [href] attribute selector (a[href]): (example)
var anchors = document.querySelectorAll('a[href]');Array.prototype.forEach.call(anchors, function (element, index) {element.href = "http://stackoverflow.com";});
If you want to change the href value of <a> elements that contain a specific value, for instance google.com, use the attribute selector a[href*="google.com"]: (example)
var anchors = document.querySelectorAll('a[href*="google.com"]');Array.prototype.forEach.call(anchors, function (element, index) {element.href = "http://stackoverflow.com";});