Link to home
Start Free TrialLog in
Avatar of bmanmike39
bmanmike39

asked on

How do i get a popupBox on mouse over?

below is my code.  I don't know why it will not work.  Any help would be appreciated.

Script tag in header:
<script type="text/javascript">
    $("a").hover(function(e) {
    $($(this).data("tooltip")).css({
        left: e.pageX + 1,
        top: e.pageY + 1
    }).stop().show(100);
}, function() {
    $($(this).data("tooltip")).hide();
});
    </script> 

Open in new window

CSS in header:
<style type="text/css">
        div {
    position: absolute;
    display: none;
    background: #ccc;
    border: 1px solid;
}
    </style>

Open in new window

Html in the body:
<a href="http://foo.com" data-tooltip="#foo">foo</a>
<br><br>
<a href="http://bar.com" data-tooltip="#bar">bar</a>

<div id="foo">foo means foo</div>
<div id="bar">bar means bar</div>

Open in new window

Avatar of Gary
Gary
Flag of Ireland image

Code works fine as is
http://jsfiddle.net/GaryC123/64UUp/

Are you including the jQuery library in the page?
Have you got a live link?
Avatar of bmanmike39
bmanmike39

ASKER

This is what i have in the head:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

Open in new window

Change your script to this and see if it works.

<script type="text/javascript">
$(function() {
    $("a").hover(function(e) {
    $($(this).data("tooltip")).css({
        left: e.pageX + 1,
        top: e.pageY + 1
    }).stop().show(100);
}, function() {
    $($(this).data("tooltip")).hide();
});
});
    </script>  

Open in new window

Thanks! This works, except when the page loads the info show for both before I mouses over then the disappear and work
Add this to your CSS
[data-tooltip*="#"] {
    display:none
}

Open in new window

now nothing shows on page at all:

my CSS code:
<style type="text/css">
   div {
    position: absolute;
    display: none;
    background: #ccc;
    border: 1px solid;
    }
    [data-tooltip*="#"] {
    display:none
}

    </style>

Open in new window

I'm wrong remove that.

This is your code exactly as you should have it with my amendments - can you see anything different since the tooltips only show on mouseover.
http://jsfiddle.net/GaryC123/4bFDT/
It's exactly as it shows but i had 2 samples one in html and one in asp.net.  the html works.

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks!!!