-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDOMRangeExample3.htm
More file actions
executable file
·44 lines (39 loc) · 1.94 KB
/
Copy pathDOMRangeExample3.htm
File metadata and controls
executable file
·44 lines (39 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<!DOCTYPE html>
<html>
<head>
<title>DOM Range Example</title>
<script type="text/javascript">
function useRanges() {
var p1 = document.getElementById("p1"),
helloNode = p1.firstChild.firstChild,
worldNode = p1.lastChild,
range = document.createRange();
range.setStart(helloNode, 2);
range.setEnd(worldNode, 3);
document.getElementById("txtStartContainer1").value = range.startContainer.nodeValue;
document.getElementById("txtStartOffset1").value = range.startOffset;
document.getElementById("txtEndContainer1").value = range.endContainer.nodeValue;
document.getElementById("txtEndOffset1").value = range.endOffset;
document.getElementById("txtCommonAncestor1").value = range.commonAncestorContainer.tagName;
}
</script>
</head>
<body><p id="p1"><b>Hello</b> world!</p>
<input type="button" value="Use Ranges" onclick="useRanges()">
<table border="0">
<tr>
<td>
<fieldset>
<legend>range1</legend>
Start Container: <input type="text" id="txtStartContainer1"><br>
Start Offset: <input type="text" id="txtStartOffset1"><br>
End Container: <input type="text" id="txtEndContainer1"><br>
End Offset: <input type="text" id="txtEndOffset1"><br>
Common Ancestor: <input type="text" id="txtCommonAncestor1"><br>
</fieldset>
</td>
</tr>
</table>
<p><strong>Note:</strong> This example uses DOM ranges and will only work in browsers that support DOM ranges. This example will fail in Internet Explorer < 9.</p>
</body>
</html>