Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
10-02-2008, 07:42 PM #1
- Join Date
- Oct 2008
- Thanked 0 Times in 0 Posts
Selection position in parent node
I'm using a contenteditable DIV to create a inline syntax highlighter. In the process of analyzing the contents of the div I am grabbing the location of the cursor. The problem is, the location returned is relative to the html tag that surrounds it. For example, if the div contains the following html:
and I place the cursor between the W and O of "world", the value of window.getSelection().anchorOffset is 1 because the cursor is between the first and second characters in the bold tag. I would like to find the the offset within the contents of the parent div (in this case it would be 7). Is there any way to do that?