Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8377073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:34:29+00:00 2026-06-09T15:34:29+00:00

Trying to figure out how to switch from one to two images then back

  • 0

Trying to figure out how to switch from one to two images then back to one with an onlick.

So far I have below which works no problem for switching to one image and back to original image. Ultimately I’m trying to get the first onclick event to be two images vertically and then click again back to the first single image.

var play = false;
    function toggle() {
        var image = document.getElementById('image')
        var scan = document.getElementById('scan');
        play = !play;
        if (play) {
            image.src = "pause.png";image.width="182";image.height="182";image.border="0";
            scan.play();
        }
        else {
            image.src = "play.png";image.width="182";image.height="182";image.border="0";   
            scan.pause();
        }
    }

and in body:

<a href="javascript:void(0)"><img onclick="toggle()" id="image" src="play.png" alt="image" width="182" height="182" style="margin:auto; position:absolute; top: 0; right: 0; bottom: 0; left: 0; border: 0;"></a>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:34:30+00:00Added an answer on June 9, 2026 at 3:34 pm

    This should work fine except, take out the width, height and border from the javascript, they’re not changing so why have it there and risk some browsers freaking out on them?

    I just put this together real quick to test and it works a treat.. I’ve commented out scan.play and pause of course but I’m assuming you’ve checked the console in your browser to see if those are throwing any errors?

    I took the <a> out and used style cursor=pointer instead for the click-able element as well.. either way works but this is neater and works from ie6 I think, ie7+ definately.

    edit: removed source block didn't achieve goal of question

    After discussion in comment there’s heaps of ways to do it, and I’d probably use jQuery but since you’re not here’s one not

    <!doctype html>
    <html>
    <head>
        <script type="text/javascript">
            var play = true;
            function toggle() {
                //var scan = document.getElementById('scan');
                var playpause = document.getElementById('playpause');
                var btnplay = playpause.getElementsByClassName('play');
                var btnpause = playpause.getElementsByClassName('pause');
                play = !play;
                if (play) {
                    btnplay[0].className = 'btn play active';
                    btnpause[0].className = 'btn pause';
                    //scan.play();
                }
                else {
                    btnplay[0].className = 'btn play';
                    btnpause[0].className = 'btn pause active';
                    //scan.pause();
                }
            }
        </script>
    
        <style>
            .btn {
                width: 182px;
                height: 182px;
                cursor: pointer;
                position: absolute;
                visibility: hidden;
            }
            .btn.active { visibility: visible; }
            .btn.play { background: url('play.png') no-repeat 0 0; }
            .btn.pause { 
                background: url('pause.png') no-repeat 0 0;
                padding: 182px 0 0 0;
            }
        </style>
    </head>
    <body>
        <div id="playpause">
            <div class="btn play active" onclick="toggle()">
            </div>
            <div class="btn pause" onclick="toggle()">
                <img src="other.png" alt="other" />
            </div>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to switch from Komodo to Eclipse. I can't figure out how to
I am trying to figure out from my code whether the Ring/Silent switch is
I'm trying to switch from two-stage rotation to one-stage rotation (to avoid the console
trying to figure out why this is happening - I have an input text
Trying to figure out which to use.
I have an iPad application which has many categorized images I need to switch
I'm trying to figure out how to get the current space # from mission
I'm trying to figure out the effectiveness of using a CDN versus hosting images
Trying to figure out how I can do this properly. The print_r looks like
Trying to figure out why my silverlight app suddenly just displays nothing (right click

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.