Skip to content

Instantly share code, notes, and snippets.

@seanbehan
Last active January 30, 2018 19:30
Show Gist options
  • Save seanbehan/457a9188d045e4e547cfccb0f825bb3b to your computer and use it in GitHub Desktop.
Save seanbehan/457a9188d045e4e547cfccb0f825bb3b to your computer and use it in GitHub Desktop.
filter dom content with vanilla javascript js
<input type="text" onkeyup="filter(this)"/>
<div class="row">blah</div>
<div class="row">blah blah</div>
<div class="row">blah blah blah</div>
<script>
function filter(e){
search = e.value.toLowerCase();
document.querySelectorAll('.row').forEach(function(row){
text = row.innerText.toLowerCase();
if(text.match(search)){
row.style.display="block"
} else {
row.style.display="none"
}
})
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment