User
User

Reputation: 1662

select the second row from the html table using jquery

I use the following jquery function for highlight the row ( using bg color ) in Html table.It was working fine.my question is how to select the second row from the table.'highlight' is a class

.highlight td {
  background: #E7EFFA;
}

$('#Tabnameabcd tr').mouseover(function() {
  if ($.trim($(this).text()) != '')
    $(this).addClass('highlight');
}).mouseout(function() {
  $(this).removeClass('highlight');
});

which means:

name    age    depart

test    12     test
test1   13     tested

here name,age,depart as a first row.that is title. next test,test1 are elements of the tabe.if i use that jquery function the title( name,age,depart ) are apply.i need to apply that jquery function only to the elements of the table not a title?how to do this?

Upvotes: 0

Views: 8842

Answers (2)

Danil Speransky
Danil Speransky

Reputation: 30453

To get second row: $('#Tabnameabcd tr').eq(1) or $('#Tabnameabcd tr:eq(1)').

To get all rows from second one (Demo: http://jsfiddle.net/pXj5F/):

$('#Tabnameabcd :nth-child(n+2)')

Also you should think about thead and tbody...

Upvotes: 4

GautamD31
GautamD31

Reputation: 28763

Try like this

$('#mytable_id tr').eq(1).(your function here);

and you want to apply for the rows not the tiltes then you can also use

$("#mytable_id td").function({
      //Play here
});

it will applicable to all the td's of your table excluding titles.you can also use ".not()" function instaed of this

Upvotes: 1

Related Questions