Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

anchorOffset property

Retrieves the starting position of a selection that is relative to the anchorNode / baseNode.

HTML5 A vocabulary and associated APIs for HTML and XHTML, Section 7.6.1Internet Explorer 9




p = object.anchorOffset


Property values

Type: Integer

The beginning position of the selection.

Standards information


The Selection.baseOffset alias for this property is only available in Microsoft Edge.

The value that is returned by anchorOffset / baseOffset usually refers to a character position within the text portion of the element.


The following example shows the anchorOffset value of a selection when you release the mouse button.

<!DOCTYPE html>
<!-- this example shows the character offset from anchor node of your selection-->
    <title>AnchorOffset Example</title>        
    <script type="text/javascript">         
      function getAnchorOffset() {
        if (window.getSelection) {                      //only work if supported
           var selection = window.getSelection ();      //get the selection object     
           var anchorOffsetProp = selection.anchorOffset;   //get the offset
           alert ( "Anchor Offset: \n" + anchorOffsetProp.toString());                                 
<div onmouseup="getAnchorOffset()">    <!-- call this function when the mouse button is released -->
        Select some text with your mouse within this field.
        When <strong>the left <em>button</em> is released</strong>, a dialog pops up with the anchor offset.
        The nested tags <strong>here and <em>there</em> can</strong> demonstrate different offsets as well.

See also

focusOffset (extentOffset)
focusNode (extentNode)
anchorNode (baseNode)



© 2017 Microsoft