focusNode property

Retrieves the element or node that contains the end of a selection.

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



HRESULT value = object.get_focusNode(IHTMLDOMNode** p);

Property values

Type: Object

the end point of a selection.

Standards information


Returns NULL if the selection does not exist. As a selection object consists of a list of Range objects, focusNode returns the value of the IHTMLDOMRange::endContainer attribute of the last Range object in the list.


The following example shows the text content that is contained within the node (or tags) that is in focus when you click a section of text.

<!DOCTYPE html>
<!-- this example displays the character offset from anchor node of your selection-->
    <title>focusNode Example</title>        
    <script type="text/javascript">         
      function getfocusNode() {
        if (window.getSelection) {                      //only work if supported
           var selection = window.getSelection ();      //get the selection object     
           var focusNodeProp = selection.focusNode;     //get the node containing the end of selection 
           alert ( "Text of current node: \n" + focusNodeProp.toString() + "\nTag name: <" + focusNodeProp.parentNode.tagName +">");                                                                                 
<div onmouseup="getfocusNode()">    <!-- call the 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 box appears with the focusNode.
        The nested tags <strong>here and <em>there</em> can</strong> demonstrate different focusNodes as well.

See also