Use Exact Search Term Only

Use Exact Search Term Only

I have a function that looks at search terms in a class and shows content that matches the term from an input.

The problem is, if I search for a1 and there's a term somewhere that's a12, then both are shown.
I want to limit the result to only exact matches.  Tried adding green text below, ie filter, but getting an undefined function.

  1. function HideFilter() { 
  2.     var txt = $('input#select_searcher_%id%').val();
  3.     txt = txt.toLowerCase();
  4.     $('[class^="searcher_stack-its"] span').filter("[class]").each(function() {
  5.       var x = ($(this).attr('class')).toLowerCase().filter(txt);
  6.       if ( x.indexOf(txt) >= 0 ) {  /* + 1 */
  7.         if ( x.indexOf(txt) != x.lastIndexOf(txt) ) {  // more than 1 match present - need to limit to exact match only
  8.           console.log('More than 1 match for ' + txt);
  9.         }
  10.         ... show matched content 
  11.       }  
  12.       else {
  13.         ... hide content that doesn't match
  14.       }  
  15.     });
  16.   }

Thanks,  Bill