# Div Element Selection Range

**URL:** <https://forum.kirupa.com/t/div-element-selection-range/320544>\
**Category:** web dev\
**Created:** [March 26, 2011, 3:42pm UTC](https://forum.kirupa.com/t/div-element-selection-range/320544 "2011-03-26T15:42:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![CliveCarrington](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/clivecarrington/32/10208_2.png) [@CliveCarrington](https://forum.kirupa.com/u/CliveCarrington)\
**Post date:** [March 26, 2011, 3:42pm UTC](https://forum.kirupa.com/t/div-element-selection-range/320544/1 "2011-03-26T15:42:30Z")

</div>

It goes like this:

I need to get the **position** of the selected text in an element.  
The element is **not** a textarea.  
I know how to get the selected **text** , but not the **position**.

The farthest I got was this:  
I can get the selected text, then get the index of it in the element’s content.  
However, this method is useless when I have more than one occurrence of the selected text.

So, how can I get the starting position of the selected text, in a non-textarea element?  
I googled this problem, but didn’t find a single answer to it.  
Maybe I just didn’t look hard enough (please link me if you know where I can get the answer).
