Hiding divs dynamically using a search

前端 未结 1 1501
南旧
南旧 2021-01-24 01:57

JSFiddle for what I have done so far http://jsfiddle.net/chQ2T/3/

As you can see, I have some divs arranged thus

相关标签:
1条回答
  • 2021-01-24 02:40

    See this updated demo: http://jsfiddle.net/chQ2T/4/

    The hide_divs() function has been slightly modified to first hide all divs and then show only those that match.

    function hide_divs(search) {
        $("#container > div").hide(); // hide all divs
        $('#container > div[id*="'+search+'"]').show(); // show the ones that match
    }
    
    $(document).ready(function() {
        $("#search_field").keyup(function() {
            var search = $.trim(this.value);
            hide_divs(search);
        });
    });
    
    0 讨论(0)
提交回复
热议问题