JS function to find the true position of an element