Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-12-2012, 02:03 AM   PM User | #1
brenkton
New to the CF scene

 
Join Date: Oct 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
brenkton is an unknown quantity at this point
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
brenkton is offline   Reply With Quote
Old 01-12-2012, 07:30 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
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 :-)
devnull69 is offline   Reply With Quote
Reply

Bookmarks

Tags
background, change, on event

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:05 PM.


Advertisement
Log in to turn off these ads.