Question:

How to make a picture change on click without javascript

by  |  earlier

0 LIKES UnLike

does anyone know how to make a picture change when you click it, and then change back when you click it again? preferably without javascript if possible

 Tags:

   Report

4 ANSWERS


  1. Can do it without clicking and using CSS and mouseover if that would work for you.

    Ron


  2. Y!A is still hosed - won't let me post code examples. I sent you an email that should help.

    Added: trying to post the code again...

    <html>

    <head>

    <style>

    #rollImg {

    background-image: url(image0.jpg);

    height: 900px;

    width: 600px;

    }

    #rollImg:hover {

    background-image: url(image1.jpg);

    height: 900px;

    width: 600px;

    }

    </style>

    <script>

    // initialize imgCnt for recording which image is

    // currently active in the JavaScript managed image

    var imgCnt = 0;

    </script>

    </head>

    <body>

    <!--

    background image for the next div will change in response

    to mouseovers under CSS control

    -->

    <div id="rollImg"></div>

    <p>

    <!--

    source attribute for next image will change in response to

    click events on the image under JavaScript control

    clicks swap {imgCnt} back and forth between 0 and 1 to

    record which image is in use

    -->

    <img src="image0.jpg"

    onclick="imgCnt = (++imgCnt)%2; this.src = (0 == imgCnt)?'image0.jpg':'image1.jpg';" />

    </p>

    </body>

    </html>

  3. Try these that I have linked for you from A List Apart: http://search.atomz.com/search/?sp-q=CSS...

  4. You can't. You'll have to use JavaScript to do something like that.

    HTML Dude's answer includes an example of how to do it (using JavaScript, which he doesn't seem to realize) that will work just fine.

Question Stats

Latest activity: earlier.
This question has 4 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.