steveosoule
3/25/2014 - 7:05 PM

Full Text search using CSS selectors to filter results

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>