How can I detect onclick() or similar for individual characters in a text?

前端 未结 6 2125
你的背包
你的背包 2020-12-20 21:49

I\'m new to Javascript and would like to modify a text string by clicking on individual characters. The string is: 0000 0000 0000 0000 representing a binary num

6条回答
  •  执笔经年
    2020-12-20 21:56

    You can't assign event to single character in text.

    You would have to assign click handler to node holding the text, and then check caret position to determine yourself which of the character has been clicked.

    One of other possible solutions could be splitting text 0000 0000 0000 0000, so that every character is wrapped in span element for example. Then you can bind click handler to those spans and easily determine which character has been clicked because click event will be fired for one, specific character.

提交回复
热议问题