title: Count words comma separated javascript
body: <p>I have try make function to display number of remaining tags in input tag, but problem is because can't find solution to count as i need, </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$("#keywords").on("keyup change input paste", function(e) {
    var content = $("#keywords").val();
    var words = content.split(",");
    var num_words = words.length;
    var limit = 7;
    if (num_words &gt; limit) {
      var lastIndex = content.lastIndexOf(",");
      $("#keywords").val(content.substring(0, lastIndex));
      return false;
    } else {
      $(".cr_keywords").text(limit + 1 - num_words + " tags remaining");
    }
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;input id="keywords" /&gt;
  &lt;div class="cr_keywords"&gt;&lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p><a href="https://i.stack.imgur.com/GJIYd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GJIYd.png" alt="enter image description here"></a></p>
  
  <p>Should be '0 tags remaining'</p>