...

View Full Version : Selection position in parent node



Sparafusile
10-02-2008, 08:42 PM
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:

Hello <b>world</b>!!

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?

Spara



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum