zoukankan      html  css  js  c++  java
  • Element Children

      The childNodes property contains all of the immediate children of the element. There is a significant difference between browsers regarding the identification of these nodes. For example, consider the following code:

    1 <ul id="myList">
    2     <li>Item 1</li>
    3     <li>Item 2</li>
    4     <li>Item 3</li>
    5 <ul>

      When this code is parsed in IE8 and earlier, the <ul> element has three child nodes, one for each of the <li> elements. In all other browsers, the <ul> element has seven elements: three <li> elements and four text nodes representing the white space between <li> elements. It's important to keep these browser differences in mind when navigating children using the childNodes property. Oftentimes, it's necessary to check the nodeType before performing an action, as the following example shows:

    1 for (var i=0, len=element.childNodes.length; i<len; i++){
    2     if (element.childNodes[i].nodeType == 1){
    3         // do processing
    4     }
    5 }
  • 相关阅读:
    人生中最重要的三位老师
    自我介绍
    秋季学习总结
    第五周学习总结
    第四周总结
    第三周基础作业
    判断上三角矩阵
    第二周作业及编程总结
    求最大值及其下标
    查找整数
  • 原文地址:https://www.cnblogs.com/linxd/p/4520788.html
Copyright © 2011-2022 走看看