Skip to content

Instantly share code, notes, and snippets.

@steveosoule
Created March 25, 2014 19:05
Show Gist options
  • Save steveosoule/9768908 to your computer and use it in GitHub Desktop.
Save steveosoule/9768908 to your computer and use it in GitHub Desktop.
Full Text search using CSS selectors to filter results
<!-- FROM: http://redotheweb.com/2013/05/15/client-side-full-text-search-in-css.html -->
<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