This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

focusOffset

Summary

Returns the number of characters that the selection’s focus is offset within the focusNode.

Property of dom/Selectiondom/Selection

Syntax

Note: This property is read-only.

var offset = selObj.focusOffset;

Return Value

Returns an object of type NumberNumber

Examples

The following example uses focusOffset to show the offset value for the end of a selection when you release the mouse button.

<!DOCTYPE html>
<html>
  <head>
<!-- this example displays the character offset from anchor node of your selection-->
    <title>Focus Offset Example</title>
    <script type="text/javascript">
      function getfocusOffset() {
        if (window.getSelection) {                      //only works if supported
           var selection = window.getSelection ();      //get the selection object
           var focusOffsetProp = selection.focusOffset;   //get the offset
           alert ( "Offset: \n" + focusOffsetProp.toString());
           }
      }
    </script>
  </head>
<body>
<div onmouseup="getfocusOffset()">    <!-- call the function when the mouse button is released -->
      <p>
        Use the mouse to select some text within this field.
        When <strong>the left <em>button</em> is released</strong>, a dialog box appears with the anchor offset.
      </p>
      <p>
        The nested tags <strong>here and <em>there</em> can</strong> demonstrate different offsets as well.
      </p>
    </div>
  </body>
</html>

Notes

Remarks

focusOffset typically refers to a character position within the text portion of the focusNode.

Syntax

Standards information

Attributions