Reputation: 5
I want to show my information at the position of pointer when I click on my element (div tag). But in the first click it's not working. It works for the second click.
<div class="active" onclick="showInfo(event)"></div>
<div class="info">This is information<div>
Upvotes: 0
Views: 176
Reputation: 8291
Demo: http://jsfiddle.net/erkaner/2L9ycL2v/2/
$(document).ready(function () {
$(".info").hide();
$(".active").click(function (event) {
$(".info").show();
$(".info").offset({
top: event.pageY,
left: event.pageX
});
});
});
Upvotes: 0
Reputation: 310
You cannot set/change the offset of the div before it has been shown.
You need show the div first, and then set the offset. This is how showInfo
should look:
showInfo = function(event){
$(".info").show().offset({top: event.pageY, left: event.pageX});
}
Here is the changed fiddle.
Upvotes: 1