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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:09:47+00:00 2026-05-13T07:09:47+00:00

I want to display div above image so that div’s top is aligned with

  • 0

I want to display div above image so that div’s top is aligned with cursor.
As cursor is moved, the div should be moved as well (right now just vertically).
In IE (pure javascript please).

<head runat="server">
    <title></title>
    <style type="text/css">
       #ToolTip{position:absolute; width: 200px;background-color:Lime; top: 0px; left: 0px; z-index:400;visibility:hidden;}
    </style>
    <script language="javascript" type="text/javascript">
        function On() {

            MoveToolTip("ToolTip", "event.y", "event.x");
            document.getElementById('ToolTip').style.visibility = 'visible';

        }
        function Off() {

            MoveToolTip("ToolTip", 0, 0);
            document.getElementById('ToolTip').style.visibility = 'hidden';
        }

        function MoveToolTip(layerName, top, left) {
               document.getElementById(layerName).style.top = (eval(top));
             //document.getElementById(layerName).style.left = (eval(left) - 360);

        }

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div id="ToolTip" >This is a test </div>   
        <a href="www.www.com"><img alt="mg" border="0" src="http://www.google.com/logos/holiday09_4.gif"  onmouseout="Off();" onmouseover="On();" /></a>

    </div>
    </form>
</body>
</html>
  • 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-13T07:09:47+00:00Added an answer on May 13, 2026 at 7:09 am

    Here’s a possible fix for your problem:

    <html>
    <head runat="server">
    <title></title>
    <style type="text/css">
        #ToolTip {
            position:absolute; 
            width: 200px;
            background-color:Lime;
            z-index:400;
            visibility:hidden;
            cursor: pointer;
        }
    </style>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <div id="ToolTip">This is a test</div>
            <a href="www.www.com">
                <img alt="mg" id="base-img" border="0" src="http://www.google.com/logos/holiday09_4.gif" />
            </a>
        </div>
        </form>
    <script language="javascript" type="text/javascript">
        function showToolTip(e) {
            e = e || window.event; // Older versions of IE handle events funny
            // Added code that compensates for the window's scroll position.
            var top = e.clientY + (window.pageYOffset || document.body.scrollTop) + 5;
            moveToolTip("ToolTip", top, e.clientX);
            document.getElementById('ToolTip').style.visibility = 'visible';
    
            // We need to cancel the center to ensure that the onmousemove event 
            // on the body element doesn't get triggered
            e.cancelBubble = true;
            if (e.stopPropagation) { e.stopPropagation(); }
            return false;
        }
        function hideToolTip() {
            moveToolTip("ToolTip", 0, 0);
            document.getElementById('ToolTip').style.visibility = 'hidden';
            return false;
        }
    
        function moveToolTip(layerName, top, left) {
            document.getElementById(layerName).style.top = (top + "px");
        }
    
        document.onmousemove = hideToolTip;
        document.getElementById("ToolTip").onmousemove = showToolTip;
        document.getElementById("base-img").onmousemove = showToolTip;
    </script>
    </body>
    </html>
    

    Things I changed:

    • Gave functions more readable names:
      • Renamed On to showToolTip
      • Renamed Off to hideToolTip
    • The event variable is now passed to the showToolTip function. This is needed to get the cursor’s x, y position
    • Added code that compensated for the window’s scroll position
    • Added return false to showToolTip and hideToolTip
    • Replaced onmouseout and onmouseover with the more widely supported onmousemove event
    • Got rid of the flicker by adding the following:
      • Added onmousemove event to document, which calls hideToolTip
      • Added onmousemove event to the tool tip div, which calls showToolTip
    • Added + "px" statement to the .style.top assignment. Some browsers get confuse if you assign an integer to a style.
    • Moved script declarations to the bottom of the page.
    • Moved event assignments to javascript and removed onmousemove attributes from the markup
    • Added the cursor: pointer style to the tool tip. This removes cursor flicker.
    • Changed code format

    I’ve also posted a working example: http://www.the-xavi.com/static/so-hover-div.html

    Hope this helps.

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

Sidebar

Related Questions

Above you see an image of stacked div's floating left. Here is that current
I want to display a div over an element (especially a link) when hovered,
I want to display a div if a certain radio button in a form
I want to display some div's in a wrap. The div have same class
I want to display a form in a Div, in alert box. How would
i want to get 'display' css value of a server side div! the code
when i hover on div#new-menu-lower ul.menuul li.menuli i want to add display block to
I have a div and I want to align in the center of that
I want to display an overlay (html div) when a user clicks on an
Currently I have the code: <!-- More html code above --> <div id="loading" style="display:

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.