You can use getBoundingClientRect() for the found text and popup and compare the sizes.
MSDN
MDN range , element
You can act directly in text ranges, but it looks like you have an element that wraps the found text to apply the selection, so I would just use this element. I think you can just pass your found text and a popup for this function to check if they overlap:
function isOverlapping (a, b) { var rectA = a.getBoundingClientRect(); var rectB = b.getBoundingClientRect(); return rectA.top < rectB.bottom && rectA.bottom > rectB.top && rectA.left < rectB.right && rectA.right > rectB.left; }
Edit: I must have too much time on my hands, because here is a fun demo: http://jsfiddle.net/gilly3/qUFLJ/4/
source share