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.
- function HideFilter() {
- var txt = $('input#select_searcher_%id%').val();
- txt = txt.toLowerCase();
- $('[class^="searcher_stack-its"] span').filter("[class]").each(function() {
- var x = ($(this).attr('class')).toLowerCase().filter(txt);
- if ( x.indexOf(txt) >= 0 ) { /* + 1 */
- if ( x.indexOf(txt) != x.lastIndexOf(txt) ) { // more than 1 match present - need to limit to exact match only
- console.log('More than 1 match for ' + txt);
- }
- ... show matched content
- }
- else {
- ... hide content that doesn't match
- }
- });
- }
Thanks, Bill