I ran into a very vague error while doing some simple jQuery DOM manipulation.
The line that triggered the error is the following:
$(this).closest(\'tr\')
I don't know what you expect the value of this
to be in your "success" handler, but I bet it's not what you think. Save this
outside the "$.ajax()" call:
var clicked = this;
$.ajax(
// ...
success: function(res) {
if (res) {
$(clicked).closest('tr').remove();
}
else {
// ...
}
}
);
// assign this to a variable
var val = this;
// Use
$(val).closest('tr').remove(); // It worked for me
Instead of :
$(this).closest('tr').remove();
I got exactly the same error on $.get() request.
For me this is the most weird bug in jQuery (my version 1.8.3).
My reason for this error was TD element with ID set to "nodeName".
After change ID value to something else, the error dissapear.
Original:
<td id="nodeName"></td>
New:
<td id="nodeNameValue"></td>
Inside your request, $(this) is not the .remove
element. It's a closure problem.
So you can assign $(this) to a variable before and call it after