Get bounding rectangle of selected text javascript

后端 未结 4 1196
情深已故
情深已故 2021-02-14 21:59

I use this code How can I position an element next to user text selection? to get the position of the selected text, but it doesn\'t work for the selected text inside an input.

4条回答
  •  孤独总比滥情好
    2021-02-14 22:42

    If you just need to get the position where the user doubleclicked, use the following snippet.

    $('#thatInput').on('dblclick', function (e) {
      alert('Position X: ' + e.clientX + '\nPosition Y: ' + e.clientY);
    });
    
    
    

提交回复
热议问题