Jquery – Microsoft JScript runtime error: Unable to get value of the property ‘defaultView’: object is null or undefined

asp.net-mvc-3jquery

i have the following script inside my asp.net mvc:-

function deleteconfirmation() {

    jAlert('The Answer was deleted succsfully', 'Deletion Confirmation');
    $(this).fadeOut('slow', function () { $(this).remove(); });

}

but when it is executed it will return the following error "Microsoft JScript runtime error: Unable to get value of the property 'defaultView': object is null or undefined" on the if(!(e=a.ownerDocument.defaultView)) inside the jquery-1.6.2.min.js.
Hint:- this error will only occur if i am using IE , it will not occur if i am using chrome or firefox!!!!
So what might be causing this ?
BR

Best Solution

The error is caused by your $(this) not referring to anything, or the window object rather. It depends on how your function is called. It's best to pass the element you want to use into the function deleteConfirmation() like so:

$("#deleteAnswer").bind("click", function() {
    deleteConfirmation(this);
});

function deleteConfirmation(element) {
    jAlert('Deleted succsfully', 'Deletion Confirmation', function() {
        alert("The user clicked ok");

        // Hides the element that caused the click event
        $(element).fadeOut('slow', function () { $(element).remove(); });
    });
}

See this jsfiddle for an example.

If you're trying to fadeOut the alert box itself, that is done by default, as you might already know.