I’m new to prototype, but fairly experienced with jQuery so it could just be I’m misunderstanding how prototype works. I’m trying to do the following
$$("tr.total_line td.total_cell").first().replace(newTotal);
but I’m getting TypeError: Cannot read property 'firstChild' of null
When I execute $$("tr.total_line td.total_cell").first() in the JS console I get a DOM element result.
Here’s the relevant markup
<tr class="total_line">
<td colspan="2">Total</td>
<td class="total_cell">$50.00</td>
<td></td>
</tr>
Since
.first()is returning a<td>element, you’ll need to insert a<td>or<th>in order for the replacement to be valid HTML.So if
newTotalis:…it should work. But if it is just:
…it doesn’t.
Or another option would be to replace the
innerHTMLof the<td>: