Here's my code, any idea why it's not working?
<script type="text/javascript">
windows.onload = function() {
function(){
document.body.style.backgroundColor = ('red');
}
};
</script>
Here's my code, any idea why it's not working?
<script type="text/javascript">
windows.onload = function() {
function(){
document.body.style.backgroundColor = ('red');
}
};
</script>
Without jquery, you can do that :
window.onload = function(){
document.body.style.backgroundColor = 'red';
};
In your code you declared a function inside the callback you give to onload but you didn't call it.
You're declaring an anonymous function but never executing it. Also, windows.onload
is probably not what you meant.
What were you expecting to happen?
If you're trying to change the background color when the document is ready:
$(document).ready(function () {
$('body').css('backgroundColor', 'red');
});
http://jsfiddle.net/jbabey/8hQyu/
Simulating a document.ready
callback without jQuery is not really a trivial task, see this question.
As far as the background color goes, this works fine:
document.body.style.backgroundColor = ('red');