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 228695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:42:14+00:00 2026-05-11T19:42:14+00:00

I have a simple web page with a simple puzzle. There are some images

  • 0

I have a simple web page with a simple puzzle. There are some images that user is supposed to drag to their designated drop zones. I use solution in JavaScript generated by DreamWeaver.

I want to add a JavaScript function that will show a correct.png or wrong.png image next to the image a user just dropped. The straightforward way to do it is to just have correct and wrong div elements for each of the draggable images. But is there a more elegant way?

Another way to put it would be:
Write a JavaScript functions Show(commonImageId, nextToImageId) and Hide(commonImageId, nextToImageId) that would be used like Show('correct', 'draggable1');.

  • 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-05-11T19:42:14+00:00Added an answer on May 11, 2026 at 7:42 pm

    Instead of having multiple divs that you show and hide, you can try this solution as well.

    Create two styles, each with a different background image set. Whenever you trap the event that a given image should be marked as correct or wrong, simply swap the style of the div, which will have the affect of switching the background image.

    Very quick (and in need of some cleanup) sample code below, you’ve got the right idea with setting the type with a function…

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>Image Swap</title>
    <script language="javascript">
    function setImage(id, value){
    document.getElementById(id).className=value;
    }
    </script>
    <style>
    .blank{
        width:80px;
        height:80px;
        float:left;
    }
    .correct{
        background-image:url('correct.gif');
        background-repeat:no-repeat;
        width:80px;
        height:80px;
        float:left;
    }
    .wrong{
        background-image:url('wrong.gif');
        background-repeat:no-repeat;
        width:80px;
        height:80px;
        float:left;
    }
    .item{
        float:left;
        height:80px;
    }
    .clear{
        clear:both;
    }
    </style>
    </head>
    <body>
    <div id="correct1" class"blank"></div><div id="item1" class="item">Item 1</div><div class="clear"></div>
    <div id="correct2" class="blank"></div><div id="item2" class="item">Item 2</div><div class="clear"></div>
    <script language="javascript">
    setImage('correct1','correct');
    </script>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple web page that displays some text and images and trying
I have a simple web page in which the user will enter some information
I have a simple web page that till now didn't need any login. It
I have a simple jQuery code that runs on a web page that has
I have a form on a simple web page that has a series of
I have a simple function to scrape a web page that is suddenly getting
I have a simple asp.net web page that contain a table with about 5
I have a simple web page that has 3 tabs in my main content
I'm having an odd issue. I have a simple web page, and for some
Ok I have a simple HTML web page. Problem is that when I specify

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.