jQuery delete table column

前端 未结 6 595
北荒
北荒 2020-12-17 00:40

I have a table and cannot change markup:

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-17 01:33

    This uses .delegate() for the handler, and a more native approach using cellIndex to get the cell index that was clicked, and cells to pull the cell from each row.

    Example: http://jsfiddle.net/zZDKg/1/

    $('table').delegate('td,th', 'click', function() {
        var index = this.cellIndex;
        $(this).closest('table').find('tr').each(function() {
            this.removeChild(this.cells[ index ]);
        });
    });
    

提交回复
热议问题