I'm trying to show a popup element when user places a mouse over an other element:
<!DOCTYPE HTML>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.2.0.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
$('#base').hover(
function handleIn(e) {
var popup = $('<img/>', {
id: 'popup',
src: 'http://placehold.it/32x32'
});
popup.css({
'position': 'absolute',
'z-index': 300,
'left': e.pageX - 30,
'top': e.pageY - 30
});
popup.mouseover(function() {
console.log('mouseover');
});
popup.mouseout(function() {
console.log('mouseout');
});
$('#base').append(popup);
},
function handleOut() {
}
);
});
</script>
</head>
<body>
<img id="base" src="http://placehold.it/256x256">
</body>
</html>
Why doesn't the popup element show up? It is added to DOM, but I don't see it.
What am I doing wrong? How can I fix it?