If you are using Vanilla JS (plain javascript) then you need to find the a
tag by looping among all a
and finding the one with href
http://google.com
and then replace it's innerHTML
.
var els = document.getElementsByTagName("a");
for (var i = 0, l = els.length; i < l; i++) {
var el = els[i];
if (el.href === 'http://google.com') {
el.innerHTML = "New Content";
}
}
Explaination:
A. document.getElementsByTagName
will return you the list of all elements matching the passed tag.
B. el.href
will get you the href
of the a
.
C. el.innerHTML = "New Content"
will set the new content.