Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft JScript runtime error: Unable to get value of the property 'defaultView': object is null or undefined

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

like image 687
john Gu Avatar asked Mar 10 '12 15:03

john Gu


1 Answers

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.

like image 83
Challe Avatar answered Oct 06 '22 03:10

Challe