Q:

js filter text


<script>
function myFunction() {
  // Declare variables

    var input, filter, 
ul, li, a, i, txtValue;
  input = document.getElementById('myInput');
  
filter = input.value.toUpperCase();
  ul = 
document.getElementById("myUL");
  li = 
ul.getElementsByTagName('li');

  // Loop through all 
list items, and hide those who don't match the search query
  for (i = 0; i < 
li.length; i++) {
    a = li[i].getElementsByTagName("a")[0];

      
  txtValue = a.textContent || a.innerText;
    
if (txtValue.toUpperCase().indexOf(filter) > -1) {
      
li[i].style.display = "";
    } 
else {
      
li[i].style.display = "none";
    
}
  }
}

</script>
 
1
<script>
    $('input[name="search_field"]').on("keyup", function() {
        filtrate($(this).val().toLowerCase());
    });

    function filtrate(searched) {
        $(".filter-key > h3").filter(function() {
            var isHidden = ($(this).text().toLowerCase().indexOf(searched) > -1) ? 'block' : 'none';
            $('.filter-key').css('display', isHidden);
        });
    }
</script>
0

New to Communities?

Join the community