Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select all table rows (tr) that contained a class (jquery)

Tags:

jquery

I have a table (#tbLog) and need to select all table rows (tr) that contain a class called private.

Thanks

like image 348
blueDroid Avatar asked Mar 17 '11 22:03

blueDroid


People also ask

How to select tr in table jQuery?

Approach 2: Use $('table tr:last') jQuery Selector to find the last element of the table. The 'table' in query looks for the table element then 'tr' is looking for all the rows in the table element and ':last' is looking for the last table row of the table.

How to get table row in jQuery?

Using .var $row = $(this). closest("tr");

How to get last tr td value in jQuery?

you have to get last child tr of table using last-child selector and then get first td child using first-child selector. Show activity on this post. References : : last.


2 Answers

Simple enough:

$("#tbLog tr.private").action();

If you have sub tables (why?), then use this instead to only select the top level trs

$("#tbLog > tbody > tr.private").action();

Note that I've included tbody in the selector as nearly all browsers will add this tag for you (it's part of the spec).

like image 81
Bojangles Avatar answered Oct 04 '22 13:10

Bojangles


This how it's done:

$('#tbLog tr.private')
like image 44
Phil Avatar answered Oct 04 '22 12:10

Phil