After several attempts and much searching, I have not yet found a solution for this one (though I am not very experienced in Javascript!). I have a table (which will be dynamically built), in which I wish to replace key words with icons. These key words will only be 'Green' or 'Yellow', however the date that is also part of the string is dynamic and needs to remain (I'll sort out its formatting later).
My HTML:
<table cellspacing="0" rules="all" border="1" style="border-collapse:collapse;">
<tr><th>Name</th><th>SOP ABC</th></tr>
<tr><td>Mary Coppen</td><td>Green10/5/18</td></tr>
<tr><td>Arlana Mycroft</td><td>Green12/6/18</td></tr>
<tr><td>Bob Litchfield</td><td>Yellow05/09/18</td></tr>
</table>
My JavaScript:
var tds = document.getElementsByTagName('td');
var Gimg = "<img src='/Content/StatusOK_16x.gif' />";
var Yimg = "<img src='/Content/StatusWarning_12x_16x.gif' />";
for (var i = 0; tds[i]; i++) {
if (tds[i].innerHTML.includes('Green')) {
tds[i].innerHTML.replace('Green', Gimg)
}
if (tds[i].innerHTML.includes('Yellow')) {
tds[i].innerHTML.replace('Yellow', Yimg)
}
}
Many thanks for any suggestions!