Skip to content Skip to sidebar Skip to footer

Change Background-color Of 1st Row In The Table

Below is my table that is getting populated with spry dataset Here is my dataset var ds1 = new Spry.Data.XMLDataSet('/xml/data.xml', 'rows/row'); Here is my jquery inside a metho

Solution 1:

If I remember right, <tr> is only describing structure. <td> represents visual part of the table. Or this is how some browsers renders them.

Therefore $("#trEven td").css("background-color", "red") should work. And preferrably you should use classes instead of ids in these kind of cases where there may exist multiple instances.

Solution 2:

Works for me (jsFiddle). What problems are you experiencing?

If your use classes instead of id's, you can use something like the following:

$('.trEven').each(function() {
    $(this).css({"background-color": "red"});
});

See for reference: jQuery API - .each()

Solution 3:

You shouldn’t be using ids for odd and even rows. id values are meant to be unique within the page.

So, I’d suggest:

<tr class="trOdd"

and:

<tr class="trEven"

and then:

$(".trEven")

If you really only want the first row in the table body to get a red background (as opposed to all the even ones), then your selector should be:

$("#tableDg tbody tr:first")

Post a Comment for "Change Background-color Of 1st Row In The Table"