Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Apr 2006
    Posts
    231
    Thanks
    9
    Thanked 1 Time in 1 Post

    onclick Background

    I have an input form that has a background image set by default. I need to make it change background on click.

    What is the codeof this? (I need something like <input bla blabla onclick="...">)

    I looked on google but they all had complicated JS.

    Thanks in Advance, Erind

  • #2
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,300
    Thanks
    28
    Thanked 275 Times in 269 Posts
    CSS:
    Code:
    .myBackground { background-image: url("image.png"); }
    HTML:
    Code:
    <input type="" onclick="this.className = 'myBackground';">
    If it has another background assigned via something with greater specificity, such as an ID, then you may need to use background-image:&#160;url("image.png")&#160;!important. You could also use this.style.backgroundImage, but I prefer to keep all of my CSS in one place.
    For every complex problem, there is an answer that is clear, simple, and wrong.


  •  

    Posting Permissions

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