anchorNode property

Returns the element or node that contains the start of the selection.

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



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

Property values

Type: Object

The start of a selection.

Standards information


Returns NULL if not successful. This is not supported by Windows Internet Explorer 8 or earlier versions. AnchorNode returns the value of the IHTMLDOMRange::startContainer attribute of the first Range object in the list. See IHTMLSelection::focusNode to find the node that contains the end of a selection.


The following example shows the text that you select, and all the text contained in the anchorNode element.

<!DOCTYPE html>
<!-- this example shows the text you selected, and all the text within the anchor node-->
    <title>AnchorNode Example</title>        
    <script type="text/javascript">         
      function getAnchorNode() {
        if (window.getSelection) {                      //only work if supported
           var selection = window.getSelection ();      //get the selection object     
           var anchorNodeProp = selection.anchorNode;   //get the node object        
           alert ( "Selected text: \n" + selection.toString() + "\nText related to the node: \n" + anchorNodeProp.toString());                                 
<div onmouseup="getAnchorNode()">                       <!-- call this function when the mouse button is released -->
        Select some text with your mouse within this field.
        When the left button is released, a dialog pops up with the anchor node.
        This is some more text to try as well.

See also