How to remove current row from table in jQuery?

后端 未结 2 1738
借酒劲吻你
借酒劲吻你 2020-12-23 23:19

I have a table in html as follows

test content
相关标签:
2条回答
  • 2020-12-23 23:42

    Try this:

    <input type="button" onClick="$(this).parent().parent().remove();">
    

    Or you can make it more generic like this:

    <script>
      $(document).ready(function()
      {
        $(".btn").click(function(){
          $(this).parent().parent().remove();
        });
      });
    </script>
    
    <tr>
      <td><input type="button" class="btn"></td>
    </tr>
    
    0 讨论(0)
  • 2020-12-23 23:48

    Nicer:

    $(this).closest('tr').remove();
    

    More on closest()

    <input type="button" onClick="$(this).closest('tr').remove();">
    

    This has the benefit of working no matter what your HTML looks like in the cell.

    0 讨论(0)
提交回复
热议问题