首页 > 其他 > 详细

Element Children

时间:2015-05-21 22:30:58      阅读:196      评论:0      收藏:0      [点我收藏+]

  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 }

 

Element Children

原文:http://www.cnblogs.com/linxd/p/4520788.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!