Definition of pageX:
pageX is the integer value in pixels for the X coordinate of the mouse pointer relative to the entire document when the mouse event is triggered. This property allows for any horizontal page scrolling.
If you put this code:
$(document.body).click(function(mouseEvent) { $("#MyDiv").css({ 'top': mouseEvent.pageY, 'left':mouseEvent.pageX }); });
It works great.
If the div is not in the desired position, it means that your DIV may have a repetition point different from the body (different from the upper left corner of the browser).
Indeed, an element with absolute positioning refers to the first source parent element. If the source parent is not found, the destination source parent is body . Perhaps you have an intermediate element with the CSS: position: relative property. This CSS property makes the element a reference for positioning and inducing a shift.
source share