Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change background color using jQuery

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>
like image 638
Susie Avatar asked Dec 21 '22 01:12

Susie


1 Answers

Use document.ready for your JS.

$(document).ready(function(){
     $('.myClass td').css({'background-color': 'yellow'}); 
});
like image 84
andi Avatar answered Dec 27 '22 01:12

andi