I have a div area that I want to change the css after the page loads. My HTML looks like the following
<div class='myArea'>
</div>
<script type="text/javascript">
$('.myArea').css('background-color',"red");
</script>
And it works. But if I move this to an external js file and reference the js file from the header, this doesn't work. The following is the js code in the external file -
function init(){
$('.myArea').css('background-color',"blue");
}
window.addEventListener('load', init, false);
What might be the reason behind this
window.addEventListener('load', init, false);?$(document).ready(function() { .. })is for