Last active
October 27, 2015 09:54
-
-
Save michaeldoye/e2159c98b84f05ab19aa to your computer and use it in GitHub Desktop.
customFilter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Requires Bootstrap CSS for .hide and .show | |
* or your own CSS, or use $(this).hide() & $(this).show() | |
* @ listObj is the list to be sorted | |
************************************************* | |
* Example Usage: $('#input').customFilter('#ul'); | |
************************************************* | |
*/ | |
jQuery.fn.customFilter = function(listObj) { | |
var $list = listObj; | |
var $input = this; | |
var $lis = $list.children(); | |
$input.on('input', function() { | |
var term = $input.val(); | |
$.each($lis, function() { | |
isContains = $(this).text().indexOf(term) > -1; | |
if( isContains ) { | |
$(this).addClass("show").removeClass("hide"); | |
} else { | |
$(this).addClass("hide").removeClass("show"); | |
} | |
}); | |
}); | |
return this; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment