CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   DOM and JSON scripting (http://www.codingforums.com/forumdisplay.php?f=15)
-   -   Background image change (http://www.codingforums.com/showthread.php?t=248583)

brenkton 01-12-2012 02:03 AM

Background image change
 
Hi there,

I'm trying to change the background image of a page (with setInterval eventually, but this is just a button to test it for now). The background image is appearing fine, and the alternate image is nice.

Code:

<body style="background-image:url('img/backg.jpg'); background-size: 100%; background-repeat:no-repeat; background-color: #8ba49e;" onload="backg();">
then this later on in the body:

Code:

<input type="button" value="button" onclick="document.body.style.backgroundImage = 'img/backg1.jpg';">
It's not working. I've also had referred to the background image in onclick as document.body.background and document.body.backgroundImage.

What's gone wrong?


Thanks for your help,
Matt

devnull69 01-12-2012 07:30 AM

Look at the code, it's all there. Inside the body tag, the CSS for background-image is
Code:

url('img/backg.jpg')
but onclick you assign this to backgroundImage
Code:

'img/backg1.jpg'
I bet, you notice the difference :-)


All times are GMT +1. The time now is 08:21 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.