Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

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

 

Syntax

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

Property values

Type: Object

The start of a selection.

Standards information

Remarks

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.

Examples

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


<!DOCTYPE html>
<html>
  <head>
<!-- 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());                                 
           }
      }                
    </script>
  </head>
<body>
<div onmouseup="getAnchorNode()">                       <!-- call this function when the mouse button is released -->
      <p>
        Select some text with your mouse within this field.
        When the left button is released, a dialog pops up with the anchor node.
      </p>  
      <p>
        This is some more text to try as well.
      </p>
    </div>
  </body>
</html>

See also

Reference
IHTMLSelection::focusNode
IHTMLSelection::focusOffset
IHTMLSelection::anchorOffset

 

 

Community Additions

ADD
Show:
© 2015 Microsoft