Element Children
2024-10-07 00:10:17
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:
<ul id="myList">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<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:
for (var i=0, len=element.childNodes.length; i<len; i++){
if (element.childNodes[i].nodeType == 1){
// do processing
}
}
最新文章
- Ajax基础
- Linux命令学习-mkdir
- jQuery页面加载后执行的事件(3种方式)
- ok6410内存初始化
- 在PyCharm里配置SubVersion
- Python报错TypeError: &#39;<;&#39; not supported between instances of &#39;str&#39; and &#39;int&#39;
- connect socket的超时设置
- python从零开始 -- 第2篇之python版本差异
- Asp.net连接数据库的配置方法
- JavaScript面试技巧(二):JS-Web-API
- cf 1132 F
- Unity shader学习之标准的Unity shader
- python中进制之间的转换
- 阿里巴巴Dubbo实现的源码分析
- 虚拟机VirtualBox安装MAC OS 10.12图文教程
- Codeforces Round #370 (Div. 2) B. Memory and Trident 水题
- ajax访问WebService跨域问题
- iOS 网络缓存总结
- 手动安装sublime插件babel-sublime
- Qt-网易云音乐界面实现-5 收藏列表,播放列表实现 QListWidget QTableWidget