Get string with class name

How can you get the first row in a table with a specific class name?

var rows = $('tr', tbl); 
0
source share
6 answers
 var rows = $('tr.classname:first', tbl); 

or

 var rows = $('tr.classname', tbl).first(); 

Docs here: http://api.jquery.com/category/selectors/

+3
source

You can use the :first selector along with class ,

Try the following:

 var rows = $('tr.someclass:first', tbl); 
+1
source
 var firstRow = $('tr.classname:first', tbl) 
+1
source

var row = $("tr.className:first", tbl); gotta do the trick.

0
source

If you save your own :first selector, you will have a valid querySelectorAll selector.

 var rows = tbl.find('tr.someClass').slice( 0, 1 ); 

or

 var rows = tbl.find('tr.someClass').eq( 0 ); 

In addition, using the context parameter $( selector, context ) is just a slower way to use find() [docs] .

0
source

You can even use the eq method for jquery if you want to iterate over a list of elements.

 var rows = $('tr.classname'); rows.eq(0);//first row rows.eq(1);//second row 
0
source

All Articles