For a literal translation...
Grab the a
elements.
var a = document.getElementsByTagName('a');
Use slice
to coerce the nodelist into an array of nodes, then use the array methods filter
and forEach
[].slice.call(a).filter(function (el) {
return el.textContent === 'Officer Title Equivalent*';
}).forEach(function (el) {
el.innerHTML = el.textContent.replace('*', '<span style="color:red">*</span>');
});
DEMO
The other option is what gurvinder hinted at in his question - no need for filter
, just a conditional:
[].slice.call(a).forEach(function (el) {
var txt = el.textContent;
if (txt === 'Officer Title Equivalent*') {
el.innerHTML = txt.replace('*', '<span style="color:red">*</span>');
}
});
DEMO
And Joseph (comments) is right - you can also do:
[].forEach.call(document.getElementsByTagName('a'), function (el) {
var txt = el.textContent;
if (txt === 'Officer Title Equivalent*') {
el.innerHTML = txt.replace('*', '<span style="color:red">*</span>');
}
});
DEMO