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 newTotal
is:
"<td>$100</td>"
...it should work. But if it is just:
"$100"
...it doesn't.
Or another option would be to replace the innerHTML
of the <td>
:
$$("tr.total_line td.total_cell").first().innerHTML = newTotal;
If replace
continues to cause problems you can try update
instead which works in a similar way.
精彩评论