How to find the selection text beginning and end positions in Javascript?

前端 未结 3 561
孤城傲影
孤城傲影 2021-01-06 03:51

I am trying to find the textual start and end of the selection. So, in the following text, if I selected \"world! What a fine\" from within \"Hello, world! What a fine day

3条回答
  •  难免孤独
    2021-01-06 04:56

    This is possible but slightly complicated with contenteditable HTML content (as opposed to text within an or