title: Exact Keyword Match for Javascript
body: <p>I have been all over SO and found many different possible solutions. I feel like there is something very easy that I am overlooking. My script on key markup filters <code>&lt;li&gt;</code> but my problem is the script will return any <code>&lt;li&gt;</code> matching the individual characters. I need the search function to return word matches not character matches.</p>
  <pre><code>function search() {
      var input, filter, ul, li, a, i, txtValue;
      input = document.getElementById(&quot;myInput&quot;);
      filter = input.value.toUpperCase();
      ul = document.getElementById(&quot;myUL&quot;);
      li = ul.getElementsByTagName(&quot;li&quot;);
      for (i = 0; i &lt; li.length; i++) {
          a = li[i].getElementsByTagName(&quot;p&quot;)[0];
          txtValue = a.textContent || a.innerText;
          if (txtValue.toUpperCase().indexOf(filter) &gt; -1) {
              li[i].style.display = &quot;&quot;;
          } else {
              li[i].style.display = &quot;none&quot;;
          }
      }
  }
  </code></pre>
  <p>Thanks for the help. Stay classy SO. Here is my <a href="https://jsfiddle.net/jkwaak/vstuym40/" rel="nofollow noreferrer">JSFiddle</a></p>