Getting text at clicked location in an HTML element

Posted by Marc on Stack Overflow See other posts from Stack Overflow or by Marc
Published on 2010-04-18T22:36:26Z Indexed on 2010/04/18 22:43 UTC
Read the original article Hit count: 336

Filed under:
|
|

I have a div element containing some text. When the user clicks a word inside that div I'd like to highlight just that word.

In order to do this I need to know what character position in the text the click occurred at, so I can then locate nearby whitespace and insert some formatting around the word.

Finding out where the click occurred within the text is the trick here. Is that kind of thing possible?

© Stack Overflow or respective owner

Related posts about html

Related posts about gettext