[H5] setStart/setEnd method of the range object, setstartsetend

Source: Internet
Author: User

[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>

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.