I want to refresh a <div> on the close of a jQuery UI Modal Dialog.
My code is:
var dialog = jQuery('#divPopup').dialog({
autoOpen: false,
height: 450,
width: 650,
modal: true,
open: function(event, ui) {
jQuery('body').css('overflow', 'hidden');
},
close: function(event, ui) {
jQuery('#divPopup').dialog('destroy').remove();
jQuery("#bodyId").load("http://www.xyz.com/ #bodyId");
}
});
But instead of replacing it, that adds the new <div> inside the old <div>:
<div id="bodyId">
<div id="bodyId">
New Response
</div>
</div>
I want to replace old div bodyId with new div bodyId.
Try to replace this:
... with this:
This works because you can use any selector after the URL. By using
#bodyId > *instead of just#bodyId, you match everything that is inside the div, instead of the div itself.You need this because
.load()will not replace an element; it will append the result of the AJAX call to the element.Alternatively, you could use
.get()to load the data and manually perform the selection, like so:Examples of both methods are online here: http://jsfiddle.net/PPvG/47qz3/