As I delve into learning jQuery, I encountered an issue while attempting to change the color
of a tr
element. Strangely, I was successful in updating other CSS attributes like font-style
. According to my understanding so far, we use the following syntax to set CSS properties and values:
$(selector).css(property,value)
Can you help me pinpoint where I may have gone wrong? Here's a snippet of my code:
HTML:
<table class="csr">
<tr><td>Row 1</td></tr>
<tr><td>Row 2</td></tr>
<tr><td>Row 3</td></tr>
</table>
<table class="aTable">
<tr><td>Row 11</td></tr>
<tr><td>Row 22</td></tr>
<tr><td>Row 33</td></tr>
</table>
CSS:
td {
color: blue;
font-weight: bold;
}
table.aTable td{
color: red;
font-weight: bold;
}
jQuery:
$( "tr:first" ).css( "font-style", "italic" );
$( "tr:first" ).css( "color", "red" );
$( "tr:first" ).css( "background-color","yellow" );
$( ".aTable tr:first" ).css( "font-style", "italic" );
$( ".aTable tr:first" ).css( "background-color","yellow" );