What is the best method in jQuery to change a particular table row into a form ?
For example to change :
<table>
<tr><td><a href="edit me">edit</a></td><td>first row</td></tr>
<tr><td><a href="edit me">edit</a></td><td>some row</td></tr>
<tr><td><a href="edit me">edit</a></td><td>last row</td></tr>
</table>
into :
<table>
<tr><td><a href="edit me">edit</a></td><td>first row</td></tr>
<tr>
<form>
<td><a href="edit me">edit</a></td>
<td><input type='text' name='a' value='b'/></td>
</form>
</tr>
<tr><td><a href="edit me">edit</a></td><td>last row</td></tr>
</table>
Update : the html we finally use :
<form>
<table>
<tr>
<td><img class="editRow"></td>
<td class="field">field to know</td>
</tr>
</table>
</form>
and the jQuery code :
$( ".editRow" ).click( function() {
var rowToEdit = $(this).parent().parent();
var field = rowToEdit.children(".field")
rowToEdit = .replaceWith( "<td></td>\
<td>\
<input type='hidden' value='"+field+"'>\
</td>"
});
Try out the function
.wrap(). For more infomation see here.