Get DOM text node from point?

前端 未结 4 1969
无人共我
无人共我 2020-12-30 06:49

Just like I can get an element from a point with document.elementFromPoint or document.getElementFromPoint, is it possible to somehow get a text no

4条回答
  •  天涯浪人
    2020-12-30 07:29

    For Firefox, you should use document.caretPositionFromPoint

    Here's a greap demo: https://developer.mozilla.org/en-US/docs/Web/API/document.caretPositionFromPoint

    For Chrome and Edge, try document.caretRangeFromPoint(x,y)

提交回复
热议问题