Jquery Insert element before <tr>

Posted by Jerry on Stack Overflow See other posts from Stack Overflow or by Jerry
Published on 2010-05-24T23:36:58Z Indexed on 2010/05/24 23:41 UTC
Read the original article Hit count: 460

Filed under:
|
|

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!

Jquery

$("#addMatch").click(function(){

    $("<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>
});

Html

<tr>
<td>some data</td>
</tr>

//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.
    <tr> 
    <td><input type="button" id="addMatch" name="addMatch" value="Add Match" </td>
    </tr>

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about html