Hi,
Hopefully a quick example will illustrate what I'm trying to do.
<table>
<tr>
<td>test</td>
<td>test</td>
</tr>
<tr>
<td>row 2</td>
<td>row 2</td>
</tr>
<tr>
<td>row 3</td>
<td>row 3</td>
</tr>
</table>
Using AJAX, I'd like to be able to replace an entire <tr> block, for
example to give:
<table>
<tr>
<td>test</td>
<td>test</td>
</tr>
</table>
<p>This is dynamic content</p>
<table>
<tr>
<td>row 3</td>
<td>row 3</td>
</tr>
</table>
I (wrongly) assumed the solution would just be:
<table>
<tr>
<td>test</td>
<td>test</td>
</tr>
<div id='mycontent'>
<tr>
<td>row 2</td>
<td>row 2</td>
</tr>
</div>
<tr>
<td>row 3</td>
<td>row 3</td>
</tr>
</table>
... then use AJAX to replace the contents of the 'mycontent' div.
Unfortunately when this renders (in Firefox anyway), the div is placed
outside of the table (above it), so any content written to the div
also appear outside of the table (I confirmed the position of the div
by putting a border around it). Perhaps this is to be expected since
in standard HTML the div shouldn't be where it is.
So my question is how I can achieve this replacement of the table row
Best,
Mark
on 2008-07-02 02:24
on 2008-07-02 02:45
1) get a reference to your tr (for example using
table.select('tr:nth-child(4)').reduce() )
2) use tr.insert({before: new Element('tr').insert(new
Element('td').update('hai')) }); //or variant of insert with innerhtml
content from ajax request
3) tr.remove();
on 2008-07-02 03:27
oh yeah, it would. I used remove/insert myself for this pattern but replace would work just as well.