This works
$('[data-department='+dept+']').closest('.person').hide();
So would expect this to show/hide the unselected elements.
$('[data-department !='+dept+']').closest('.person').hide();
It does not work as expected. Even when hard-coded.
$('[data-department!=8]').closest('.person').hide();
$('[data-department !='+dept+']')will match many elements even the ones which don't have anydata-departmentattribute... e.ghtml, body, etc...You'd have better to filter it using:$('[data-department]').filter('[data-department !='+dept+']').closest(...)