body = document.getElementsByTagName('body'); page = 1; body.style.backgroundImage = 'images/' + page + '.jpg';
Uncaught TypeError: Cannot set property 'backgroundImage' of undefined
document.getElementsByTagName('body')[ 0 ]
Uncaught TypeError: Cannot read property 'style' of undefined
body = document.getElementsByTagName('body'); console.log( body );
<body> === содержание страницы === </body>
undefined
<script> onload = function(){ var body = document.getElementsByTagName('body')[ 0 ]; body.style.backgroundImage = 'url("http://javascript.ru/forum/images/ca_serenity/misc/logo.gif")'; }; </script>
window.onload = function () { document.body.style.backgroundImage = 'url("my.jpg")'; }