collapse.htm (899B)
1 <!DOCTYPE HTML> 2 <meta charset=utf-8> 3 <title>Selection: Collapse the selection using collapse()</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script> 7 window.onload = function() { 8 test(function() { 9 var selection = window.getSelection(); 10 var p1 = document.getElementById("p1"); 11 12 var range = document.createRange(); 13 range.selectNode(p1); 14 selection.addRange(range); 15 selection.collapse(p1, 0); 16 17 assert_equals(selection.anchorNode, p1); 18 assert_equals(selection.anchorOffset, 0); 19 assert_equals(selection.focusNode, p1); 20 assert_equals(selection.focusOffset, 0); 21 assert_equals(selection.isCollapsed, true); 22 assert_equals(selection.rangeCount, 1); 23 assert_equals(selection.toString(), ""); 24 }); 25 }; 26 </script> 27 <div id=log></div> 28 <p id="p1">Add a range to the selection</p> 29 </body> 30 </html>