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

For example, I have many lines of data, each of which has an edit button with an edit-button class.

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

In the dialog callback for one of the β€œbuttons,” I would like to pass the string as an argument.

In particular, I would like to get the parent ID attribute .edit-button tr (in the table).

Usually I can do something line by line:

 var tr = $(element).parents("tr:first"); 

... to get the element tr .

How will this be achieved?

+4
source share
2 answers

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

eventObj will give you access to eventObj.target, which you can use to determine which DOM element started it.

Literature:

* An example refers to using an event to get .type, but you can also get .target from it.

+2
source

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');

+1
source

Source: https://habr.com/ru/post/1336881/


All Articles