Parse the firstChild array element of the children object in the dom. Use of lastChild

Source: Internet
Author: User

Copy codeThe Code is as follows:
<! -- Children object array element example -->
<Html>
<Body>
<Table id = "tbl">
<Tbody> <tr> <td> Row 1 column 1 </td> <td> Row 1 column 2 </td> </tr>
<Tr> <td> Row 2 column 1 </td> <td> Row 2 column 2 </td> </tr>
</Tbody>
</Table>
<Input onclick = "alert (document. all. tbl. children (0). children (0). innerHTML)" value = "children (0)" type = "button">
<Input onclick = "alert (document. all. tbl. children (0). children (1). innerHTML)" value = "children (1)" type = "button">
<Input onclick = "alert (document. all. tbl. children (0 ). children (1 ). children (0 ). innerHTML) "value =" children (2) "type =" button ">
<Div id = test>
<A> </a>
<Table> </table>
</Div>

<Script>
Alert (test. children [0]. tagName)
Alert (test. children [1]. tagName)
</Script>

</Body>
</Html>

<! -- In DOM, the elements on the entire page are tree structures.
Children represents the child node array of the object -->

Document. all. tbl. children (0). children (0). Explanation of innerHTML
Document. all. tbl. children (0) locate the first subnode of the table <tbody>
Document. all. tbl. children (0 ). children (0) locates the first subnode of the first subnode of the table <tr>, print the result <td> Row 1 column 1 </td> <td> Row 1 column 2 </td>


Document. all. tbl. children (0 ). children (1 ). innerHTML, print the result <td> Row 2 column 1 </td> <td> Row 2 column 2 </td>


Document. all. tbl. children (0). children (1). children (0). innerHTML prints the result row, 2 columns, and 2 columns.


<! -- FistChild, lastChild example -->
<Html>
<Body>
<Table id = "tbl">
<Tbody> <tr id = "tr1"> <td> Row 1 column 1 </td> <td> Row 1 column 2 </td> </tr>
<Tr> <td = "tr2"> Row 2 column 1 </td> <td> Row 2 column 2 </td> </tr>
</Tbody>
</Table>
<Input onclick = "alert (document. all. tbl. firstChild. firstChild. innerHTML)" value = "children (0)" type = "button">
<Input onclick = "alert (document. all. tbl. firstChild. lastChild. innerHTML)" value = "children (1)" type = "button">
<Input onclick = "alert (document. all. tbl. firstChild. lastChild. firstChild. innerHTML)" value = "children (2)" type = "button">
<Div id = test>
<A> </a>
<Table> </table>
</Div>

<Script>
Alert (test. firstChild. tagName)
Alert (test. lastChild. tagName)
</Script>

</Body>
</Html>

Document. all. tbl. firstChild: locate the first subnode of the table <tbody>
Document. all. tbl. firstChild. firstChild: locate the first subnode of the table. <tbody>
<Tr id = "tr1">
Document. all. tbl. firstChild. firstChild. innerHTML: <td> Row 1 column 1 </td> <td> Row 1 column 2 </td>


Document. all. tbl. firstChild. lastChild: locate the first subnode of the table. <tbody>
<Tr id = "tr2">
Document. all. tbl. firstChild. lastChild. innerHTML: <td = "tr2"> Row 2 column 1 </td> <td> Row 2 column 2 </td>


Document. all. tbl. firstChild. lastChild. firstChild. innerHTML:
Row 2 column 2

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.