[H5] setStart/setEnd method of the range object, setstartsetend
1. setStart: indicates the starting position of the range object of a node;
2. setEnd: the end position of the range object of a node;
Example:
<Body> <div id = "div"> the first text </div> <input type = "butt on" onclick = "dele () "value =" delete "> <script> function dele () {var div = document. getElementById ("div"); var range = document. createRange (); var content = div. firstChild; range. setStart (content, 1); range. setEnd (content, 7); range. deleteContents () ;}</script> </body>
3. setStartBefore: used to set the start position of a node to the start position of the range object;
4. setStartAfter: used to set the end position of a node to the start position of the range object;
5. setEndBefore: used to set the start position of a node to the end position of the range object;
6. setEndAfter: used to set the end position of a node to the end position of the range object;
Example:
<Body>
<Table id = "table" border = "1" cellspacing = "0" cellpadding = "0">
<Tr>
<Td> Table 1 </td>
<Td> Table 1 </td>
<Td> Table 1 </td>
</Tr>
<Tr>
<Td> Table 2 </td>
<Td> Table 2 </td>
<Td> Table 2 </td>
</Tr>
<Tr>
<Td> Table 3 </td>
<Td> Table 3 </td>
<Td> Table 3 </td>
</Tr>
</Table>
<Input type = "button" onclick = "btn ()" value = "Delete the first line">
<Script>
Function btn (){
Var table = document. getElementById ("table ");
Var rangeDiv = document. createRange ();
If (table. rows. length> 0 ){
Var row = table. rows [0];
RangeDiv. setStartBefore (row );
RangeDiv. setEndAfter (row );
RangeDiv. deleteContents ();
}
}
</Script>