Determine the position index of a character within an HTML element when clicked

后端 未结 4 1608
误落风尘
误落风尘 2020-12-09 09:49

I have an HTML element with only visible text inside. This example is a

element, but it could be a ,

4条回答
  •  醉梦人生
    2020-12-09 10:43

    You could, using JavaScript, break each character into it's own SPAN tag and add an onclick event for each. Then, read the x, y position from the event data when the SPAN is clicked.

    As well, you will have access to the character clicked with event.target.innerHTML

提交回复
热议问题