Skip to content

Instantly share code, notes, and snippets.

@Spellhammer
Created June 10, 2021 17:09
Show Gist options
  • Save Spellhammer/319a23e833936366e4fb247546c9e9c8 to your computer and use it in GitHub Desktop.
Save Spellhammer/319a23e833936366e4fb247546c9e9c8 to your computer and use it in GitHub Desktop.
Filterable List - JS
jQuery.expr[":"].CIcontains = jQuery.expr.createPseudo( function (arg) {
return function (elem) {
return jQuery(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
};
});
jQuery('#filter').keyup(function() {
var curr_text = jQuery(this).val();
filterResults(curr_text);
})
jQuery('.fast-filter input[type="checkbox"]').change( function() {
var thisID = jQuery(this).attr('id');
jQuery('.fast-filter input[type="checkbox"]').each( function() {
if( jQuery(this).attr('id') != thisID) {
jQuery(this).prop('checked', false);
}
})
if( jQuery(this).is(':checked') ) {
var curr_text = jQuery(this).data('search-term');
filterResults(curr_text);
} else {
filterResults('');
}
})
function filterResults(curr_text) {
jQuery('.card').hide();
jQuery('.card:CIcontains("' + curr_text + '")').show();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment