Show divs based on text search

后端 未结 4 1608
情深已故
情深已故 2020-12-28 15:49

I have a text input search that is supposed to filter divs based on the title of the div. Here is the code that is not working:

$(\'.contact-name\').each(fun         


        
4条回答
  •  旧巷少年郎
    2020-12-28 16:17

    try this

    var txt = $('#search-criteria').val();
    $('.contact-name:contains("'+txt+'")').show();
    

    documentation for :contains() Selector

    fiddle example : http://jsfiddle.net/WBvTj/2/

    UPDATE CASE INSENSITIVE:

    var txt = $('#search-criteria').val();
    $('.contact-name').each(function(){
       if($(this).text().toUpperCase().indexOf(txt.toUpperCase()) != -1){
           $(this).show();
       }
    });
    

    fiddle Example : http://jsfiddle.net/WBvTj/4/

提交回复
热议问题