title: Group and count HTML elements by data attribute in jQuery
body: <p>I'm trying to group each instance of a data attribute into a list from the number of occurrences of each attribute in a page, using jQuery. Similar to grouping categories or tags in a news section.</p>
  
  <p>For example, I would like to create something like this:</p>
  
  <ul>
  <li>Category 1 (5)</li>
  <li>Category 2 (3)</li>
  <li>Category 3 (1)</li>
  </ul>
  
  <p>from this html:</p>
  
  <pre><code>&lt;ul class="categories"&gt;
     &lt;li data-category="category-1"&gt;Category 1&lt;/li&gt;
     &lt;li data-category="category-1"&gt;Category 1&lt;/li&gt;
     &lt;li data-category="category-1"&gt;Category 1&lt;/li&gt;
     &lt;li data-category="category-1"&gt;Category 1&lt;/li&gt;
     &lt;li data-category="category-1"&gt;Category 1&lt;/li&gt;
     &lt;li data-category="category-2"&gt;Category 2&lt;/li&gt;
     &lt;li data-category="category-2"&gt;Category 2&lt;/li&gt;
     &lt;li data-category="category-2"&gt;Category 2&lt;/li&gt;
     &lt;li data-category="category-3"&gt;Category 3&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>How can I achieve this in jQuery? Is it even possible?</p>