Given this table:
<table border="1" width="200" id="table1" cellspacing="0" cellpadding="0" style="border-collapse: collapse" bordercolor="#CB2F7F">
<tr id="st_ppp">
<td width="60%" class="totalLabels">Price per piece</td>
<td width="39%" align="right" class="totalElements">unknown</td>
</tr>
<tr id="st_qty">
<td width="60%" class="totalLabels">Quantity</td>
<td width="39%" align="right" class="totalElements">unknown</td>
</tr>
<tr>
<td width="60%"> </td>
<td width="39%" align="right"> </td>
</tr>
<tr>
<td width="60%" class="subTotalLabel">Sub-Total:</td>
<td width="39%" align="right" class="subTotal">unknown</td>
</tr>
</table>
I’d like to do something like the following pseudo code:
document.getElementById("st_ppp").[td whose class is totalElements].innerHTML="NewPrice";
document.getElementById("st_qty").[td whose class is totalElements].innerHTML="NewQty";
I’m open also to suggestions of any other changes to the HTML that will make the JS easier to work with.
If you’re not worried about compatibility with Internet Explorer 7 and earlier,
querySelectoris perfect for that (but if you go this way, credits to @Sirko instead):If you’re already using jQuery, it’s excellent for that:
Otherwise, a loop will work: