Try the following: Simple but case sensitive though
jQuery('#searchBox').on('keyup change', function() { var search = $('#searchBox').val(); $('h4').hide(); $('h4[id*='+ search + ']').show(); });
Strike>
See if that helps. I will not use id to store string comparisons, as the name may be the same for multiple users, and you may end up with multiple h4 with the same identifier. SO I use attribute data and jquery data here.
jQuery('#searchBox').on('keyup change', function() { var search = $('#searchBox').val(); $('h4').hide().filter(function(_,oj){ return $(oj).data('key').toLowerCase().indexOf(search.toLowerCase()) > -1;
Committing code will mean that. There is no contains function and pairs of other typos.
Demo
jQuery('#searchBox').on('keyup change', function() { var search = $('#searchBox').val(); //for each h4 $('h4').each(function(){ var h4id = this.id; if (h4id.indexOf(search) > -1) //if your are trying to match the text() then do //if ($('#'+h4id).text().indexOf(search) > -1) $(this).show(); else $(this).hide(); }); });
source share