Q: how to get pixel coordinates of an element on computer screen I would like to know the left and top position of an html element on the screen.
I tried with this code that gives me the position of an element inside a document:
var position = $('#elem').position();

but what I want is to know if there is a function that finds the position on the screen, or if there is a way to know the coordinates of this point on the screen: 
Thank you in advance!

A: You are probably looking for Element.getBoundingClientRect().

The returned value is a TextRectangle object, which contains read-only
  left, top, right and bottom properties describing the border-box in
  pixels. top and left are relative to the top-left of the viewport.

For example, this is the result for question element on not scrolled page:
document.querySelector("#question").getBoundingClientRect()


{
    "height": 633,
    "width": 728,
    "left": 431.5,
    "bottom": 844,
    "right": 1159.5,
    "top": 211
}

And a bit scrolled:
{
    "height": 633,
    "width": 728,
    "left": 431.5,
    "bottom": 10,
    "right": 1159.5,
    "top": -623
}


A: use offset api
Get the current coordinates of the first element, or set the coordinates of every element, in the set of matched elements, relative to the document.
instead position the coordinates are relative to the parent element

A: you need to define what positon you want to find top left
check documentation Position
var position = $('#elem').position();
alert(position.left + ' ' + position.top)

