www.webdeveloper.com
Results 1 to 6 of 6

Thread: Changing background image with a button

  1. #1
    Join Date
    Sep 2010
    Posts
    3

    Changing background image with a button

    I am trying to make a button that would change the background image whenever somebody clicks it.

    I have tried something along the lines of this:

    <input type="button"
    value="Pattern1"
    onClick="background-image: url(background.png);background-repeat: no-repeat;">
    and,

    <input type="button"
    value="Pattern2"
    onClick="background: url(background.png);background-repeat: no-repeat;">
    as you can see, I am a beginner at coding in general so any help is appreciated.

    My assumption to why it doesn't work is that I am combining javascript with CSS, but I am most likely wrong.

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Do you mean the background image of the button or of the document?
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #3
    Join Date
    Sep 2010
    Posts
    3
    of the document itself

  4. #4
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    <input type="button"
    value="Pattern1"
    onclick="document.body.style.cssText+=';background-image: url(background.png);background-repeat: no-repeat;';">
    At least 98% of internet users' DNA is identical to that of chimpanzees

  5. #5
    Join Date
    Sep 2010
    Posts
    3
    Quote Originally Posted by Fang View Post
    Code:
    <input type="button"
    value="Pattern1"
    onclick="document.body.style.cssText+=';background-image: url(background.png);background-repeat: no-repeat;';">
    Thank you so much for your help. I was trying to "thank post" or "rep+", but I can't seem to find it.

  6. #6
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    I was trying to "thank post" or "rep+", but I can't seem to find it.
    We don't have that in this forum.
    Pleased to have helped.
    At least 98% of internet users' DNA is identical to that of chimpanzees

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles