I have a dialog with a checkbox inside on a jsp page. This dialog opens when a hyperlink is clicked.
The functionality that I am trying to achieve is governed by following rules:
- The dialog should only close when the checkbox inside is checked.
- If the dialog is reopened and the checkbox is already checked, the user can click anywhere on the page to close it.
If the dialog is reopened and the checkbox is not checked or unchecked, then user can only close the dialog by checking the checkbox.
function closeDialog() { var checked = $('.checkboxClass').attr('checked'); $('.ui-widget-overlay').live('click', function() { if(checked){ $('#'+divId).dialog('close'); }else{ <!-- since unchecked, dialog should not be closed--> //$(document).unbind('click'); //$('.ui-widget-overlay').unbind('click'); $('.ui-widget-overlay').die('click'); } }); } <!-- This detects if checkbox is clicked--> $('.checkboxClass').live('click', function() { var checked = $('.checkboxClass').attr('checked'); if(checked){ $('#'+divId).dialog('close'); } });
I have tried all things to perform step 3, ie, prevent the dialog from being closed if user clicks anywhere outside dialog, but it gets closed. Any Ideas?
I am using jQuery 1.4 and hence would prefer to retain .live()
which i know is deprecated.