Created
September 19, 2013 15:17
-
-
Save joshbeckman/6625059 to your computer and use it in GitHub Desktop.
Client-side full-text filter in CSS
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
<input type="text" placeholder="filter" id="filter"> | |
<ul class="contacts"> | |
<li class="filterable" data-index="all my lower case search terms"> | |
All my lower case search terms | |
</li> | |
<li class="filterable" data-index="lowerlowercasecase"> | |
Lower lower case case | |
</li> | |
<!-- add as much data as you want, add the selector class and add the terms in data-index --> | |
</ul> | |
<style id="filter_style"></style> | |
<script type="text/javascript"> | |
var filterStyle = document.getElementById('filter_style'); | |
document.getElementById('filter').addEventListener('input', function() { | |
if (!this.value) { | |
filterStyle.innerHTML = ""; | |
return; | |
} | |
filterStyle.innerHTML = ".filterable:not([data-index*=\"" + this.value.toLowerCase() + "\"]) { display: none; }"; | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment