Take the 2-minute tour ×  Hi all I am trying to insert a block
element Insert something before another . I am not sure if I am
using the right method but here is my code. Hope you guys can
help. Thanks!        $("<td>New
insert</td>").insertBefore("#addMatch").closest('tr');
return false;   //this would insert the <td>New insert</td>
before the                                    //<td><input
type="button" id="addMatch" name="addMatch" value="Add
//Match" </td> but not <tr>   <td>some data</td>  //can't tell
how many tr would show before the last "addMatch" button. It's
dynamic.  // I want the <td>New insert</td> show up here.
<td><input type="button" id="addMatch" name="addMatch"
value="Add Match" </td> share|improve this question  1 Answer 1
up vote 10 down vote accepted  <td> should always be in a <tr>.
I would probably make your function like this:
$(this).parents('tr:first').before('<tr><td>New
Insert</td></tr>');     return false; share|improve this answer
Instead of