mercredi 14 avril 2021

jQuery filter with imputs (include / inside checkbox)

I would like to ask if anyone knows how to solve my problem. Filtering works for every other (I want to use case insensitive), but the checkbox does not appear after searching for "food". I need to create a list of categories with checkboxes. If you search for a category, you can immediately check the checkbox

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("#myInput").on("keyup", function() {
    var value = $(this).val().toLowerCase();
    $("#myDIV *").filter(function() {
      $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
    });
  });
});
</script>
</head>
<body>

<h2>Filter</h2>
<!--Type something in the input field to search for a specific text inside the div element with id="myDIV" -->
<input id="myInput" type="text" placeholder="Search..">

<div id="myDIV">
  <p>dog</p>
  <div>master20</div>
  <button>Button</button>
  <p>Welcome5</p>
  <label class="important_class_for_me">Food
    <input type="checkbox">
    <span class="my_custom_checkmark"></span>
  </label>
</div>
  
</body>
</html>




Aucun commentaire:

Enregistrer un commentaire