简体   繁体   中英

jQuery - How to count the number of hidden or visible rows in a table

I have the following jQuery that counts the number of rows in my table. However, some of the table rows might be hidden because of a filter I have in place. How can I change the function below to count the number of visible rows only?

function UpdateCount() {
    var totalRows = $('#listingTable tbody tr').length;
    $("#rowCount").text(totalRows.toString() + " sightings")
}

You can use :visible if they are truly hidden, not just without visibility

function UpdateCount() {
    var totalRows = $('#listingTable tbody tr:visible').length;
    $("#rowCount").text(totalRows + " sightings");
}

You can use :visible selector:

Selects all elements that are visible.

function UpdateCount() {
    var totalRows = $('#listingTable tbody tr:visible').length;
    $("#rowCount").text(totalRows.toString() + " sightings")
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM