Note that there are some explanatory texts on larger screens.

plurals
  1. POno children selection
    text
    copied!<p>I have some htmls, where some tags does not have any children, and I want to identify them and count the number of those tags.</p> <p>I have tried the following and it doesn't seem to work:</p> <pre><code>var count = 0; $("th[class=gridlabel]").each(function(){ if($("th[class=gridlabel]").children().length&lt;1) { count++; } }); return count; alert(count); </code></pre> <p>not sure what's the issue here.</p> <hr> <p>I have added some additional scripts from the html source code, I want to ensure the "count" will only count the first two tags, for "answer 3" and "answer 4", as their tags do not have children:</p> <pre><code> &lt;tr&gt; &lt;th class="gridlabel"&gt;answer 3&lt;/th&gt; &lt;td headers="q12_header1" class="gridcell"&gt;&lt;input&gt;&lt;div&gt;&lt;span&gt;answer 3&lt;/span&gt;&lt;label&gt;1&lt;/label&gt;&lt;/div&gt;&lt;/td&gt; &lt;td headers="q12_header2" class="gridcell"&gt;&lt;input&gt;&lt;div&gt;&lt;label&gt;&lt;/label&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th class="gridlabel"&gt;answer 4&lt;/th&gt; &lt;td headers="q12_header1" class="gridcell"&gt;&lt;input&gt;&lt;div&gt;&lt;span&gt;answer 4&lt;/span&gt;&lt;label&gt;1&lt;/label&gt;&lt;/div&gt;&lt;/td&gt; &lt;td headers="q12_header2" class="gridcell"&gt;&lt;input&gt;&lt;div&gt;&lt;label&gt;&lt;/label&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th class="gridlabel"&gt;other specify 1&lt;input&gt;&lt;label&gt;other specify 1&lt;/label&gt;&lt;/th&gt; &lt;td&gt;&lt;input&gt;&lt;div&gt;&lt;span&gt;other specify 1&lt;/span&gt;&lt;label&gt;1&lt;/label&gt;&lt;/div&gt;&lt;/td&gt; &lt;td&gt;&lt;input&gt;&lt;div&gt;&lt;label&gt;2&lt;/label&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload