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).
精彩评论