开发者

how to get the next given parent

If you got a开发者_如何学Go TD in a table, how can you then get the parent TABLE?


Actually, you want .closest():

var $table = $("yourTdSelector").closest("table");

.parents() will return all tables that are ancestor, so if you had a table within a table, you'll get both <table> elements with no reference as to which is the actual closest parent.


There's also $('td').closest('table'): http://api.jquery.com/closest/


Take a look at jQuery.parents():

var $table = $("yourTdSelector").parents("table");

EDIT:

Actually, disregard this, .closest() is indeed the better option here (as shown in the other answers).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜