Skip to content

Instantly share code, notes, and snippets.

@jasonlfunk
Created June 3, 2014 20:09
Show Gist options
  • Save jasonlfunk/911d58bb329e9c889ce8 to your computer and use it in GitHub Desktop.
Save jasonlfunk/911d58bb329e9c889ce8 to your computer and use it in GitHub Desktop.
Quick jQuery dom filter
$("[data-search-dom]").each(function(i,e) {
var timeout = null;
var $e = $(e);
var $target = $($e.data("search-dom"));
if($target.length > 0) {
$e.keyup(function() {
var search = $.trim($e.val());
window.clearTimeout(timeout);
timeout = setTimeout(function() {
if(search) {
$target.filter(":contains('"+search+"')").fadeIn(100);
$target.filter(":not(:contains('"+search+"'))").fadeOut(100);
}
}, 500);
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment