Created
July 23, 2013 09:22
-
-
Save kezabelle/6061118 to your computer and use it in GitHub Desktop.
Quick and dirty filtering in JavaScript ... inefficient!
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
var previous_result = ''; | |
// listen to an input ... | |
$('#filter-input').live('keyup', function(evt) { | |
var filtering_by = $(this).val().toLowerCase(); | |
if (previous_result === filtering_by) { | |
return; | |
} | |
previous_result = filtering_by; | |
// eg: labels, list items, whatever. | |
var possibles = $('#nodes-to-filter'); | |
possibles.each(function(evt) { | |
var $this = $(this); | |
var text = $this.text().toLowerCase(); | |
// hide or show the parent element. | |
if (text.indexOf(filtering_by) !== -1) { | |
$this.parent().show(); | |
} else { | |
$this.parent().hide(); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment