-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDOMRangeExample5.htm
More file actions
executable file
·29 lines (25 loc) · 1.03 KB
/
Copy pathDOMRangeExample5.htm
File metadata and controls
executable file
·29 lines (25 loc) · 1.03 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
<!DOCTYPE html>
<html>
<head>
<title>DOM Range Example</title>
<script type="text/javascript">
function extractContent() {
var p1 = document.getElementById("p1"),
helloNode = p1.firstChild.firstChild,
worldNode = p1.lastChild,
range = document.createRange();
range.setStart(helloNode, 2);
range.setEnd(worldNode, 3);
var fragment = range.extractContents();
p1.parentNode.appendChild(fragment);
}
</script>
</head>
<body>
<div>
<p id="p1"><b>Hello</b> world!</p>
</div>
<input type="button" value="Extract Content" onclick="extractContent()">
<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>