I am trying to change the background color with jQuery. What am I doing wrong? I know this can be done with CSS a lot easier but I am trying to do it with jQuery.
Link to jsfiddle. I am trying to change the background of "Hi" to yellow.
window.onload=function(){
$('.myClass td').css({'background-color': 'yellow'});
}
<table>
<tr class="myClass">
<td>Hi</td>
</tr>
<tr>
<td>Bye</td>
</tr>
</table>
Use document.ready for your JS.
$(document).ready(function(){
$('.myClass td').css({'background-color': 'yellow'});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With