0

For work I need to check if some text was clicked, then in the spot that was clicked append an 'anchor' for a sticky note. So I would like to add an event listener to the text node so that way the function will only run if text is clicked.

Th event listener is currently on the text nodes container which is causing issues if you click inside the container, but not on text nothing will happen. Is there a way to only add an event listener to the text or another work around to find out if text was clicked on?

  • Please show what you've got so we can get a specific idea of what's happening. – mykaf May 16 '23 at 20:58
  • Does this answer your question? [textNode addEventListener](https://stackoverflow.com/questions/4789342/textnode-addeventlistener) – pilchard May 16 '23 at 20:59
  • You can add listeners as they inherit from EventTarget, but they don't fire events themselves. – pilchard May 16 '23 at 21:01
  • @pilchard I was looking at that before I asked my question... I was hoping there might be a way around it some way. I feel like there should be a way to know if someone clicked on text or not. – jacobcurry27 May 16 '23 at 21:01
  • also see: [Get the full word that cursor is touching (or within) JavaScript](https://stackoverflow.com/questions/61598927/get-the-full-word-that-cursor-is-touching-or-within-javascript). Lots of duplicates either employing span elements or contenteditable to utilize selection api. – pilchard May 16 '23 at 21:04
  • Please provide enough code so others can better understand or reproduce the problem. – Community May 17 '23 at 04:11

0 Answers0