a.nodeName is undefined
I've looked this up but the explanations didn't seem at all clear to me.
function deleteThisRow() {
$(this).closest('tr').fadeOut(400, function(){
$(this).remove();
});
}
<tr>
<td>blah blah blah</td>
<td>
<img src="/whatever" onClick="deleteThisRow()">
</td>
</tr>
The
this
keyword in your function does not refer to the element which was clicked on. By default it would refer to the highest element in the DOM, which would be thewindow
.To fix this you can use an unobtrusive event handler, instead of an outdated
on*
event attribute, as they run under the scope of the element which raised the event. Try this: