title: Count nested divs in JavaScript
body: <p>Hey I need to count the nested divs with a given class name. For example:</p>
  
  <pre><code>&lt;div id = "divA"&gt;
      &lt;div class = "anotherName"&gt;&lt;/div&gt;
      &lt;div class = "toBeCounted"&gt;&lt;/div&gt;
      &lt;div class = "someName"&gt;&lt;/div&gt;
      &lt;div class = "toBeCounted"&gt;&lt;/div&gt;
      &lt;div class = "toBeCounted"&gt;&lt;/div&gt;
      &lt;div class = ""&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div id = "divB"&gt;
      &lt;div class = ""&gt;&lt;/div&gt;
      &lt;div class = "toBeCounted"&gt;&lt;/div&gt;
      &lt;div class = ""&gt;&lt;/div&gt;
      &lt;div class = "toBeCounted"&gt;&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>So if I want to count "toBeCounted" I would get 3 for divA and 2 for divB.</p>