I'd like to toggle the visibility of certain rows in a table based on the value of a drop-down box. I already have classes for each of the rows, so I decided to add userType as an attribute (which is generated by PHP) to the <tr>'s. However, when I use the same function I used for toggling the visibility of the rows using their class selectors, it doesn't work with $('tr[userType="User"]');. I've searched around for why this selector isn't returning the right array, but haven't had any luck. Any help would be much appreciated.
Function:
function toggleUserTypeRows(){
var selected = $('#userTypeDropDown').val();
switch (selected){
case 'User':
var $rows = $('tr[userType="User"]');
$rows.show();
$('tr[userType="Admin"]').hide();
break;
case 'Admin':
var $rows = $('tr[userType="Admin"]');
$rows.show();
$('tr[userType="User"]').hide();
break;
default:
var $rows = $('#tableUsers tr');
$rows.show();
}
}