On my page (let's call it page A) I have a jQuery dialog with the id customOrderEdit. Within the dialog I load another page (let's call it page B) using $("#customOrderEdit").load("/url/to/page.php").
Now I want to close the dialog using a custom button, but it won't close. I've tried so many things (found on google, stackoverflow, etc.) but none of them seem to work. It doesn't matter if the code to close the dialog are on page A or B, as long as it closes I'm happy.
Code I tried on page A:
$("body").on('click', '.cancelUpdateOrder', function(){
console.log("Test"); //it displays the test console log, but it doesn't close
$("#customOrderEdit).dialog( "close" );
return false;
});
Code I tried on page B:
$(".cancelUpdateOrder").on('click', function(){
$('#customOrderEdit').dialog('close');
return false;
});
I've also tried to call the click function differently:
$(".cancelUpdateOrder").click(function(){ }});$(".cancelUpdateOrder").live('click', function(){ }});$(".cancelUpdateOrder").on('click', function(){ }});.
And the closing part:
$(".ui-dialog").dialog( "close" );window.parent.$('#customOrderEdit').dialog('close');$('#customOrderEdit', window.parent).dialog("close");
And probably some more I can't remember.
Does anyone know what I'm doing wrong and can provide me the right code?
The class selector can return a list of objects, then you can try to iterate with them using each:
If doesn't work, you can try to put a console.log to track if you are reaching the right elements.
Hope it helps