Given two abitrary HTML elements A and B in the same document, how can I find out which one is \"closer\" to the user (i.e. if they overlap, which one is obscuring the other
You could get the elements' dimensions and offsets, and then use document.elementFromPoint() to determine which one is the element rendered on top.