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

  • SEARCH
  • Home
  • 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 7742759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:21:28+00:00 2026-06-01T09:21:28+00:00

Ok, I am using JavaScript to control an image swap so that when someone

  • 0

Ok, I am using JavaScript to control an image swap so that when someone clicks on the image, it changes to a “lit” version of the image. The code to do this within the link tag is onclick="changeto('wdl')" and I added onmouseover="changeto('wdl')" to the link so when you hover over it, it lights up as well.

Now, where the problem comes in, naturally, is when I added onmouseout="changeto('wdd')" which is the unlit version of the image. What happens here of course is when I hover over it, it lights up, when I move the cursor away it changes to the non lit version. But when you click on it it changes the image to the lit version as it should, but because of the onmouseout command, it changes to the unlit version.

What I want is to be able to hover on the image and have it light up. If you click it and move the mouse away it stays lit, but if you don’t click it and move the mouse away it stays on the “off” image.

Any help appreciated, I am stumped here. I was going to try to use some sort of if (!this) type of thing, but I honestly just don’t know.

  • 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-01T09:21:29+00:00Added an answer on June 1, 2026 at 9:21 am

    I see two solutions:
    1. Declare separate CSS class for onclick event that is defined below wdd (or uses !important.
    2. Use a flag variable which is set to true in onclick and then tested in onmouseout:

    onclick="changeto('wdl');flag=true;" 
    onmouseout="if (!flag) changeto('wdd')"
    

    Here is a simple example with CSS and Javascript:

    <!DOCTYPE html>
    <html lang="en">
        <head>
            <meta charset="utf-8" />
            <title>Example</title>
            <style>
                #whl {
                    background: #e0e0ff;
                    line-height: 150px;
                    text-align: center;
                    width: 150px;
                }
                #wdl {
                    background: #e0ffe0;
                    line-height: 150px;
                    text-align: center;
                    width: 150px;
                }
                #whl:hover {
                    background: #ffcccc;
                }
                #wdl:hover {
                    background: #ffcccc;
                }
                #whl.selected {
                    background: #ffcccc;
                }
                #wdl.selected {
                    background: #ffcccc;
                }
            </style>
            <script>
                function doClick(el) {
                    document.getElementById("whl").className = document.getElementById("whl").className.replace( /(?:^|\s)selected(?!\S)/ , '' );
                    document.getElementById("wdl").className = document.getElementById("wdl").className.replace( /(?:^|\s)selected(?!\S)/ , '' );
                    el.className += "selected";
                }
            </script>
        </head>
        <body>
            <div id="whl" onclick="doClick(this);">WHL</div>
            <div id="wdl" onclick="doClick(this);">WDL</div>
        </body>
    </html>
    

    It works with colours and in your case you will have to replace colours with background images (in the CSS).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a slideshow using Javascript and an asp.net image control.
I am using a javascript code to print an image with some text as
I want to hide the Next button on my ASP.NET Wizard control using JavaScript.
I am looking for a fancy Slider control using JQuery/Javascript. The native JQuery slider
I want to call a JavaScript function through C#, using a WinForm's WebBrowser control.
I'm generating HTML elements on the fly using javascript. These controls are located within
Using JavaScript I open the pop window and parent window is inactive at this
Using JavaScript, how do I create an HTML table that can "accept" numeric matrix
Someone can explain this error? Error Creating Control - head Object reference not set
I have an asyncfileupload control that I'm using from the ajaxcontroltoolkit. On the file

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.