-
-
Save fzaninotto/2da116a146457aa7e78c to your computer and use it in GitHub Desktop.
Full-text search engine 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="search" id="search"> | |
<style id="search_style"></style> | |
<script type="text/javascript"> | |
var searchStyle = document.getElementById('search_style'); | |
document.getElementById('search').addEventListener('input', function() { | |
if (!this.value) { | |
searchStyle.innerHTML = ""; | |
return; | |
} | |
// look ma, no indexOf! | |
searchStyle.innerHTML = ".searchable:not([data-index*=\"" + this.value.toLowerCase() + "\"]) { display: none; }"; | |
// beware of css injections! | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment