0

Back from this issue

Multiple Dialog

I was able to solve the issue but now problem is that it removes the div so when I access that Div it give error. It gives error because when I open dialog it works fine after removing on close it gives e.rror

I don't want to removed jQuery('#divPopup') If there is only one div present. If multiple jQuery('#divPopup') are there remove() should be working fine.

jQuery('.register_button_class').live('click',function () {

    var iFrameobj = createIframe('',iframeUrl);
    jQuery('#divPopup').html(iFrameobj);
    createDialogWithClose(url,'#bodyId');

    return false;
});

Dummy Div for Dialog Popup, This get removed, when Click on Close Jquery Ui Popup. So when I say

jQuery('#divPopup').html(iFrameobj);

It gives error.

<div id="divPopup"></div>
Community
  • 1
  • 1
AliMan
  • 107
  • 2
  • 2
  • 10

2 Answers2

1

I'm assuming that your function:

createDialogWithClose(url, '#bodyId');

removes the div id="divPopup" each from the DOM when you close it.

I would suggest not initially including that div in your markup and change your function to create the div and append it to the DOM when it runs. Then remove like you're already doing.


jQuery('.register_button_class').live('click',function () {

    var iFrameobj = createIframe('',iframeUrl);
    jQuery("body").append("<div id='divPopup' />").html(iFrameobj);
    createDialogWithClose(url,'#bodyId');

    return false;
});

It's hard to tell what other issues you may be running into with this bit of code that you posted, however, jQuery("body").append("<div id='divPopup' />").html(iFrameobj); will create the divPopup each time the function runs. So, when you close it and it gets removed it will just get created again the next time that button is clicked.

EDIT: How to check if a Div exists -

if ($("#divPopup").length > 0){
   // do something here
}
ryanmarc
  • 1,670
  • 1
  • 10
  • 9
  • Thx for the Reply, ANy other way to check the Instance of DIv.?? So that I can check If there is one Instance then I wont remove Div – AliMan Jan 17 '12 at 09:02
  • 1
    I've edited my original answer to add how you would check if a div exists already. If this answer was the solution, accept it so that other people with the same question might benefit. – ryanmarc Jan 17 '12 at 15:10
  • An important point to remember is that if $("#divPopup").length > 1 then your DOM is invalid as per w3c because "The id attribute specifies a unique id for an HTML element (the value must be unique within the HTML document)" – Ali Nov 02 '12 at 17:08
0

I solved like this

var length = jQuery('#divPopup').length;
if(length>1)
{
    jQuery('#divPopup').dialog('destroy').remove();

}else
{
    jQuery('#divPopup').dialog('destroy');
}
AliMan
  • 107
  • 2
  • 2
  • 10