I am having troubles with getting a popup to come up at the exact location of my mouse click. I want to be able to click a DIV (that is inside a table cell) and for a popup to show up whenever this div is clicked.
Right now I have the popup working, however no matter what I try the popup DIV is half way down the page.
HTML
<ul class="customdropdown" style="display:none;" id="xxx<?php echo $fetch['unit_no']; ?>" role="menu" aria-labelledby="menuitems">
<li role="presentation"><a role="menuitem" tabindex="-1" href="#"</i>Link 1</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#"</i>Link 2</a></li>
</ul>
JQUERY
$(document).ready(function () {
$('#myDiv<?php echo $fetch['unit_no']; ?>').click(function (e) {
var myDiv = document.getElementById('myDiv<?php echo $fetch['unit_no']; ?>');
var leftx = e.pageX-myDiv.offsetLeft;
var topy = e.pageY-myDiv.offsetTop;
$("#xxx<?php echo $fetch['unit_no']; ?>")
.css({
position: 'absolute',
left: leftx,
top: topy,
display: 'block'
})
});
});
Screenshot of what is happening below:
Is this to do with the positioning of the DIV?