The closest one finds the closest ancestor element, not the closest one in the DOM. In your case tr, containing the input does not have a class, so the selector does not work. You probably want to find the closest one tr, and then find the previous previous brother of this trwith the class.
$(this).closest('tr').prevAll('tr.category-item:last');
source
share