Show divs based on text search

后端 未结 4 1613
情深已故
情深已故 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:00

    The find method takes a JQuery selector as parameter. I doubt your search_criteria text input will contain that. Assuming it will contain some substring of the DIV's title, then try this:

    var txt = $('#search-criteria').val();    
    $('.contact-name').each(function(i, e){
      if($(e).attr("title").indexOf(txt)>=0) $(e).show();
    });
    

提交回复
热议问题