Retrieves the element or node that contains the end of a selection.
Property of dom/Selectiondom/Selection
SyntaxNote: This property is read-only.
var oNode = selObj.focusNode;
Return Value
Returns an object of type DOM NodeDOM Node
Returns the node in which the selection ends.
ExamplesThe 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>
<html>
<head>
<title>focusNode Example</title>
<script type="text/javascript">
function getfocusNode() {
if (window.getSelection) {
var selection = window.getSelection ();
var focusNodeProp = selection.focusNode;
alert ( "Text of current node: \n" + focusNodeProp.toString() + "\nTag name: <" + focusNodeProp.parentNode.tagName +">");
}
}
</script>
</head>
<body>
<div onmouseup="getfocusNode()">
<p>
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.
</p>
<p>
The nested tags <strong>here and <em>there</em> can</strong> demonstrate different focusNodes as well.
</p>
</div>
</body>
</html>
Notes Remarks
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 endContainer attribute of the last Range object in the list.
Syntax Standards informationMozilla Developer Network : [Selection.focusNode Article]
Microsoft Developer Network: [focusNode Property Article]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4