Skip to main content
added 361 characters in body
Source Link
Andy
  • 63.6k
  • 13
  • 72
  • 99

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>'); } }); 

DEMODEMO

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

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

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

added 386 characters in body
Source Link
Andy
  • 63.6k
  • 13
  • 72
  • 99

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

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

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

Source Link
Andy
  • 63.6k
  • 13
  • 72
  • 99

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