How do I search in multiple Checkbox fields?

2

I have several Checkbox

<div class="checkbox">
   <label>
   <input type="checkbox" class="chkItem" name="Selected" value="1" /> A
   </label>
</div>
<div class="checkbox">
   <label>
   <input type="checkbox" class="chkItem" name="Selected" value="2" /> B
   </label>
</div>
<div class="checkbox">
   <label>
   <input type="checkbox" class="chkItem" name="Selected" value="3" /> C
   </label>
</div>

How do I create a "Search" search for the letter "C" for example and hide all other checkboxes?

    
asked by anonymous 12.09.2014 / 18:36

1 answer

1

I had a search of these here and it was easy to adapt in your html:

$("#search").bind("change keyup", function() {
    var search_str = $(this).val().toLowerCase();
    if (search_str != "") {
        $(".checkbox").hide();
        $(".checkbox").filter(function( index ) {
            return $( this ).text().toLowerCase().indexOf(search_str) != -1;
        }).show();
    } else {
        $(".checkbox").show();
    }
});

Running on JSFiddle

    
12.09.2014 / 19:15