开发者

Using jQueryUI Dialog, how can I get the element that opened the dialog?

For example, I have many rows of data, each with an "edit" button with a class "edit-button".

I have a .live() click handler on for .edit-button elements.

In a dialog callback for one of the "buttons", I would like to pass the row as an argument.

Specifically, I'd like to get the ID attribute of the .edit-button's parent tr (in a table).

Usually, I might do something along the lines of:

var tr = $(element).parents("tr:fi开发者_Python百科rst");

...to get the tr element.

How would this be achieved?


When binding with .live('click', function(eventObj)

eventObj will give you access to the eventObj.target that you can use to determine which DOM element fired it.

References:

  • http://api.jquery.com/live/ (look for "Multiple Events" *)
  • http://api.jquery.com/bind/ (look for "The Event object")
  • http://api.jquery.com/category/events/event-object/

* the example relates to using event to get .type, but you can also get .target from it.


Store the element (this in the click handler) somewhere so you can access it later. If you want the parent TR, use var tr = $(this).closest('tr');

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜