Removing an item in jQuery
so that the item is completely removed from the DOM. It's great. Your question is how to make sure that the item is really deleted.
I would use the .parent () method for this. Because if an item is removed from the DOM, it will no longer have a parent. This may be faster than $("html").has(bg)because it does not need to go through the entire DOM tree.
bg = $('<div class="dialog_bg"></div>');
$('#'+elm).append(bg);
bg.remove();
if(bg.parent().length == 0) {
// removed succesfully
} else {
// still somewhere in the dom
}
// tells the garbage collector to free the memory because there no way to access the element anymore
bg = null;