开发者

Get table row object from table or vice versa

Hey guys I'm creating a jquery plugin and I'm trying to either get the table row selector from table or the table from table row selector.

$("#table tr").myPlugin();

$("#table").myPlugin();

Basically within the plu开发者_开发问答gin I need to access the table selector or row selector. So within the first version with the row I need this.

var table = $('#table');

Or within the regular table version I need this.

var row = $('#table tr');

How would I do this? Thanks.


From within the plugin this.selector will give you the selector string, or the selector method that was used, like .children(td). this.context will give you the original context of the selector.

$('tr').children('td');

//inside plugin
this.selector; // "children(td)"
this.context;  // "tr"
this.prevObject; //[tr] parent table row

you can play around with different selectors here: http://jsfiddle.net/MkCxD/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜