Long story short I'm making a greasemonkey script. The pages I work on have this specific table with various values depending on the page.
<table class="billing dead">
<tbody>
<tr>
<th>Index:</th>
<td>Long alpha numeric value here</td>
</tr>
<tr>
<th>Status:</th>
<td class="status">This text is red to denote urgency.</td>
</tr>
</tbody>
</table><!-- end billing dead -->
What I need to do is change the text "Index:" to something else, whether it be a button or a link depending on the situation. I'm just having a hard time actually locating the item via Javascript.
Looking around I found this: How to Get Element By Class in JavaScript? which provided me with this code:
function replaceContentInContainer(matchClass,content)
{
var elems = document.getElementsByTagName('*'), i;
for (i in elems)
{
if((" " + elems[i].className + " ").indexOf(" " + matchClass + " ") > -1)
{
elems[i].innerHTML = content;
}
}
}
That replaces the whole table, however it's the closest question/answer to my situation; it's just not quite right. Once I've found the table with that method linked above, is there a way to access the elements of that specific table? I've tried arbitrarily changing
elems[i].innerHTML = content;
into
elems[i][0].innerHTML = content;
which quickly taught me that elems[i]
isn't a node of nodes. Is there an easy way to do what I'm looking for?