开发者

Close a jQuery UI Dialog from an element inside of it?

开发者 https://www.devze.com 2022-12-19 00:10 出处:网络
Here\'s a quick question that\'s probably simpler than I\'m thinking. I\'m populating a jQuery UI dialog with the resulting html from an $.ajax() call.In certain cases that html includes a button tha

Here's a quick question that's probably simpler than I'm thinking.

I'm populating a jQuery UI dialog with the resulting html from an $.ajax() call. In certain cases that html includes a button that when clicked, I want to close the containing dialog.

Assuming that I don't know anything about the element that was specified to be the dialog using $("#element").dialog()...(i.e. I have no idea what the "#element" se开发者_如何学编程lector is from the dialog's inner content) - What's the best way to close the dialog from an element clicked inside of it?


Use closest()

$(this).closest('.ui-dialog-content').dialog('close');


Something like:

$('a.close').click(function(e) {
    $(this).closest('.dialog').dialog('close');
});
0

精彩评论

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