Last active
January 30, 2018 19:30
-
-
Save seanbehan/457a9188d045e4e547cfccb0f825bb3b to your computer and use it in GitHub Desktop.
filter dom content with vanilla javascript js
This file contains hidden or 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" 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