How to create popup boxes next to the links when mouse over them?
Here is the simpliest solution.
HTML:
<a href="http://foo.com" data-tooltip="#foo">foo</a>
<a href="http://bar.com" data-tooltip="#bar">bar</a>
<div id="foo">foo means foo</div>
<div id="bar">bar means bar</div>
CSS:
div {
position: absolute;
display: none;
...
}
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();
});
$("a").hover(function(e) {
$($(this).data("tooltip")).css({
left: e.pageX + 1,
top: e.pageY + 1
}).stop().show(100);
}, function() {
$($(this).data("tooltip")).hide();
});
div {
position: absolute;
display: none;
border: 1px solid green;
padding:5px 15px;
border-radius: 15px;
background-color: lavender;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
<a href="http://foo.com" data-tooltip="#foo">foo</a>
<a href="http://bar.com" data-tooltip="#bar">bar</a>
<div id="foo">foo means foo</div>
<div id="bar">bar means bar</div>
DEMO: http://jsfiddle.net/8UkHn/
Have you considered using a "title" attribute in this case?
<a href="http://foo.com" title="foo means foo"> foo </a>
See if this fits your need.
What it does is, when you move mouse over the link "foo", a small box containing "foo means foo" will appear next to the mouse pointer.