The following code is used to open up a modal window and display some message. At its right top corner, a remove button is appended. When it's clicked, the modal window is closed. The first invocation is fine, but second the remove button expands another half wide, then another, then another, even every time it's removed from the modal window when the button is clicked. How to prevent the remove button keeping expanding? The code is from book Applied jQuery develop and design. Please check the attached picture to look at the modal window after several invocations. Thanks,
Code:
function dispMsg(msgstr) {
$('body').append('<div id="re" class="errorModal">'+msgstr+'</div>');
/*
* define the margins so that the modal is centered properly on the screen
* we add 80px to the height/width to accomodate for the padding and border
* width defined in the css
*/
var modalMarginTop = ($('#re').height() + 60) / 2;
var modalMarginLeft = ($('#re').width() + 60) / 2;
/* apply the margins to the modal window */
$('#re').css({
'margin-top' : -modalMarginTop,
'margin-left' : -modalMarginLeft
});
/* fade in the modal window and add a close button to it */
$('#re').fadeIn().prepend('<a href="#" class="close_error"><img src="images/close_button.png" class="close_button" title="Close Window" alt="Close" /></a>');
/*
* close the error modal and remove
*/
$('a.close_error').live('click', function() {
$('#re').fadeOut(function() {
$('a.close_error').remove();
$('#re').remove();
});
});
/* fade out modal and clear form
$('#registerWindow, #modalShade').fadeOut(function() {
$('#registerForm input[input*="pe"]').val('');
}); */
return;
}
How are you? Padonak, nice to hear from you. Thanks for your response. I change the code as you suggest, but the problem is still there. I just don't understand, it's removed, why it's still there.
Can we modify the following code to something else to overwrite, not to prepend, to solve the problem? Can you show me how it can be overwritten. Thanks,
Bookmarks