Link to home
Start Free TrialLog in
Avatar of jamesktaylor
jamesktaylor

asked on

getSelection Start/End position

Hi there, been searching the web with no avail.  Basically, what I'm trying to do is get the start/end position of highlighted text.  So, say for example we have:

Hello my name is Jimmy

The word 'Hello' is highlighted, button clicked.  Start position would be 0, end 4 or so.

Positions are pretty much all I need to know, the selection would initially be made with getSelection() or createRange() for compatibility.

I've seen some methods such as anchorOffset, focusOffset, anchorNode, anchorOffset, but I just can't seem to get them working.  JS newbie, the DOM documentation and web documentation isn't really helping.  

Any thoughts would be highly appreciated.
ASKER CERTIFIED SOLUTION
Avatar of Pravin Asar
Pravin Asar
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jamesktaylor
jamesktaylor

ASKER

This looks to be pretty close to what I'm looking for, however I can't seem to get this to work on a non-double click.  With an href or a button, it's killing the selected text and... Well, making people double click nothing doesn't work.  Any ideas why a button/href fail on this?