Mike
Mike

Reputation: 2923

Given a jQuery object in a variable containing the rows of a table, how can I find out how many are visible?

I have this JS code :

var trs = $("#internalActivities > tbody > tr");

I want to be able to use the variable trs to find the number of visible rows in the table.

This is the code that I am looking to convert to use the variable

$("#internalActivities > tbody > tr:visible").length

I am looking for a code like this: trs:visible.length. Of course this code won't work but I want the syntax that works.

Thanks

Upvotes: 0

Views: 42

Answers (1)

krishwader
krishwader

Reputation: 11381

Won't this work ?

trs.filter(":visible").length

From the docs:

Reduce the set of matched elements to those that match the selector or pass the function's test.

More info here at filter documentation.

Upvotes: 2

Related Questions