jquery selector to count the number of visible table rows?

前端 未结 4 506
死守一世寂寞
死守一世寂寞 2020-12-13 23:18

I\'ve got this html:

blah
相关标签:
4条回答
  • 2020-12-13 23:39

    You can use the :visible selector and .length like this:

    var numOfVisibleRows = $('tr:visible').length;
    

    If the <table> itself isn't visible on the screen (:visible returns false if any parent is hidden, the element doesn't have to be hidden directly), then use .filter(), like this:

    var numOfVisibleRows = $('tr').filter(function() {
      return $(this).css('display') !== 'none';
    }).length;
    
    0 讨论(0)
  • 2020-12-13 23:39

    $("tr:visible") gets you the results of the visible rows, and I think you can then do .length

    0 讨论(0)
  • 2020-12-13 23:52

    You can also view particular table visible rows

     var totalRow =  $('#tableID tr:visible').length;
     var totalRowWithoutHeader = totalRow-1;
    

    The totalRowWithoutHeader gives the total row count excluding header row.

    0 讨论(0)
  • 2020-12-14 00:00

    $('tr:visible').length

    0 讨论(0)
提交回复
热议问题