Results 1 to 2 of 2

Thread: Clic div within page => background color/image change?

  1. #1
    Join Date
    Jan 2010
    Posts
    26
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Question Clic div within page => background color/image change?

    I am looking for a script which performs the following:

    When I click on a small div box, I want the background of the whole page to change (not the background of the div).

    I would like the background to change to another color or another image pattern.

    How do I accomplish this?

  2. #2
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    </head>
    
    <body>
    <div style="position:absolute;left:100px;top:100px;height:50px;width:50px;background-Color:blue;"
    onclick="document.body.style.backgroundColor='red';"
     ></div>
    <div style="position:absolute;left:400px;top:100px;height:50px;width:50px;background-Color:green;"
    onclick="document.body.style.backgroundImage='url(http://www.vicsjavascripts.org.uk/StdImages/One.gif)';"
     ></div>
    </body>
    
    </html>
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •