OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html id='root'> |
3 <body> | 3 <body> |
4 This text won't be selected because it isn't editable. | 4 <span id='target'>16-char header. This text is initially selected. 16-char foote
r.</span> |
5 <div id='target' contenteditable="true">16-char header. This text is initially s
elected. 16-char footer.</div> | |
6 This text won't be selected because it isn't editable. | |
7 <script> | 5 <script> |
8 function select() { | 6 function select() { |
9 var text = document.getElementById('target').firstChild; | 7 var text = document.getElementById('target').firstChild; |
10 var range = document.createRange(); | 8 var range = document.createRange(); |
11 range.setStart(text, 16); | 9 range.setStart(text, 16); |
12 range.setEnd(text, 48); | 10 range.setEnd(text, 48); |
13 window.getSelection().addRange(range); | 11 window.getSelection().addRange(range); |
14 } | 12 } |
15 window.onload = select; | 13 window.onload = select; |
16 </script> | 14 </script> |
17 </body> | 15 </body> |
18 </html> | 16 </html> |
19 | 17 |
OLD | NEW |