开发者

Get table row object from table or vice versa

开发者 https://www.devze.com 2023-03-23 19:52 出处:网络
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.

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

精彩评论

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