Search code examples
javascriptjquerydatatablesecmascript-5

Count Span(s) in cells with a specific class within a table (ES5)


I'm trying to count all cells that have a certain class and contains span with a specific class

Here is my td structure:

<td class="Yellow">
 Hello Kitty 
<span class="glyphicon glyphicon-exclamation-sign" title="Invalid!"></span>
</td>

I want to be able to loop through the entire table and get all .Yellow > span.glyphicon-exclamation-sign

and finally, do a .count()

I have tried table.cells('.Yellow').count() but this only considers td with .Yellow


Solution

  • You can count it by following...

    let count=document.querySelectorAll('.Yellow > span.glyphicon-exclamation-sign').length