...">

# Tr with style property is empty

Here is my html

<table id="tbl1"> <tbody > <tr class="hide_grid_header"></tr> <tr style="display: none;"></tr> <tr style="display: none;"></tr> <tr ></tr> <tr style=""></tr> <tr ></tr> <tr style=""></tr> <tr ></tr> <tr style="display: none;"></tr> </tbody> </table> 

From this, I want to count tr, which does not have a style property OR with the style = "" property.

I use the code below, but it gives me a score of 8 instead of 5.

  var docs = jQuery("#tbl").find('tbody').find('tr:visible'); alert(docs.length); 
+6
source share
4 answers
 $('tr').filter(function(){ return !$(this).attr('style'); }).length; 
+4
source
 var len = $('tr').filter(function(){ return !$(this).attr('style'); }).length; 

http://jsfiddle.net/6pHt6/

+2
source

You can try .filter() :

 console.log($('table tr').filter('[style]').length); 

.filter() filters out a collection of objects.

CHECKOUT FIDDLE WITH FILTER USED

.not() :

 console.log($('table tr').not('[style]').length); 

This will output all the tr length which doesn't have a style attributes.

CHECKOUT FIDDLE NOT USED

0
source

Selecting each collection separately :

 var $tr_blank_style = $('tr[style=""]'); // with style="" var $tr_no_style = $('tr:not([style])'); // no style attribute at all var $tr_count = $tr_blank_style.length + $tr_no_style.length; 


Using filter to select both together :

 var $tr_count = $('tr').filter(function() { return $(this).is('[style=""],:not([style])'); }).length; 
0
source

All Articles