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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:04:44+00:00 2026-05-26T01:04:44+00:00

i have a single div 100px X 300px. What’s the easiest way in JavaScript

  • 0

i have a single div 100px X 300px. What’s the easiest way in JavaScript so when I hover over the div i show an image and then when i leave the div the image disappears.

for starters i thought the following would get me started but i can’t seem to remove the image properly

    <script type="text/javascript">

        function MouseOver_Event(elementId) {
            var imgToCreate = document.createElement('img');
            imgToCreate.setAttribute('id', 'imgHandle');
            imgToCreate.setAttribute('src', elementId + '.png');
            imgToCreate.setAttribute('onmouseout', 'MouseOut_Event('+elementId+')');
            var targetDiv = document.getElementById(elementId);
            targetDiv.appendChild(imgToCreate);
            targetDiv.removeAttribute('onmouseover', 'MouseOver_Event');
        }
        function MouseOut_Event(elementId) {
            var imgToRemove = document.getElementById('imgHandle');
            var targetDiv = imgToRemove.parentNode();
            if (imgToRemove != null)
                targetDiv.removeChild(imgToRemove);
            targetDiv.setAttribute('onmouseover', 'MouseOut_Event(' + elementId + ')');
        }
    </script>
</head>
<body>
<div id="div1" onmouseover="MouseOver_Event(this.id)"></div>
<div id="div2" onmouseover="MouseOver_Event(this.id)"></div>
<div id="div3" onmouseover="MouseOver_Event(this.id)"><img src="Div3.png" alt="test" onmouseout="MouseOut_Event(parentNode's id or something)" /></div>
</body>
  • 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-26T01:04:45+00:00Added an answer on May 26, 2026 at 1:04 am

    Why don’t you use CSS instead ?
    For example:

    #div1{background:none;}
    #div1:hover{background:url('src/div1.png') no-repeat;}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

At my personal website while viewing a single post, i have an overview DIV,
What is a good way to set up a single container div with some
I have a situation like this. I need to repeatedly overload the single div
I have two sets of JQuery Accordions within a single DIV tag. At the
i have single php dynamic page that load image each time app user is
I have a simple splash page that I want to fadeIn a single div.
Is there a way to assign multiple backgrounds to a single element DIV. The
I have a webpage which content(single div and a lot of text with formatting)
I have a single column layout where the column is a centered div with
I have an single threaded, embedded application that allocates and deallocates lots and lots

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.