Skip to content

Instantly share code, notes, and snippets.

@fzaninotto
Last active June 12, 2021 00:27
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 10 You must be signed in to fork a gist
  • Save fzaninotto/2da116a146457aa7e78c to your computer and use it in GitHub Desktop.
Save fzaninotto/2da116a146457aa7e78c to your computer and use it in GitHub Desktop.
Full-text search engine in CSS
<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