开发者

How to get the following DOM element using jQuery

开发者 https://www.devze.com 2022-12-17 06:19 出处:网络
var rows = $(\".sometable tr:last\"); var cells = $(\".sometable tr:last td\").filter(function() { return $(this).html().length == 0 });
var rows = $(".sometable tr:last");
    var cells = $(".sometable tr:last td").filter(function() { return $(this).html().length == 0 });

I want to get the first empty cell in the last row of my table.

The table is rendered from the server and it is html table. I can iterate to cells and get the first cell if there are elements available. But I do not want to do that.

Is there any other way without looping? After getting first element i wan开发者_运维问答t to call jquery .html('set') method to set some html data.


$('.sometable tr:last td:empty:first')

However, :last and :first are non-standard jQuery-specific selectors which means you won't get the benefit of fast native selectors. Also, you're going to have trouble if there can be nested tables.

If you make sure you've got a <tbody> around the rows in your markup (for XHTML and browser fixup compatibility), you could better say:

$('.sometable>tbody>tr:last-child>td:empty')[0]
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号