-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.html
More file actions
40 lines (36 loc) · 908 Bytes
/
1.html
File metadata and controls
40 lines (36 loc) · 908 Bytes
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
<!DOCTYPE html>
<html>
<head>
<title>Selection Test</title>
<style>
button {
margin-right: 10px;
}
</style>
</head>
<body>
<h1>Select Some Text</h1>
<div>
<textarea style=width:2in;height:3in>
Lorem dolor sit amet
<u>consectetur</u> <i>adipiscing</i> <u>elit</u>
vel
</textarea>
</div>
<button onclick="
// Get the current selection
const selection = window.getSelection();
// Get the start and end nodes of the selection
const startNode = selection.anchorNode;
const endNode = selection.focusNode;
// Get the start and end offsets of the selection
const startOffset = selection.anchorOffset;
const endOffset = selection.focusOffset;
// Set the new start and end offsets
const newStartOffset = startOffset + 1;
const newEndOffset = endOffset + 1;
// Set the new selection range
selection.setBaseAndExtent(startNode, newStartOffset, endNode, newEndOffset);
">mv</button>
</body>
</html>