JS-firstChild,firstElementChild,lastChild,firstElementChild,nextSibling,nextElementSibling
<body>
<ul id="ul1">
<li>11111</li>
<li>22222</li>
<li>33333</li>
<li>44444</li>
</ul>
</body>
1,firstChild:第一个子节点。
标准下:firstChild会包含文本类型的节点
非标准下(IE7以下):fistChild只包含元素节点
var oUl = document.getElementById('ul1');
alert( oUl.firstChild ); //标准下显示[object Text],非标准下是[object HTMLLIElement]
alert( oUl.firstElementChild )//标准和非标准都是 [object HTMLLIElement]
注意兼容性:
var oFirst = oUl.firstElementChild || oUl.firstChild;
oFirst.style.background = 'red';
2,lastChild:最后一个子节点(同上)
兼容性:
var oLast = oUl.lastElementChild || oUl.lastChild;
oLast.style.background = 'yellow';
3,nextSibling:下一个兄弟节点
var oNext = oFirst.nextElementSibling || oFirst.nextSibling;
oNext.style.background = 'blue';4,previousSibling:上一个兄弟节点
var oPrev = oLast.previousElementSibling || oLast.previousSibling;
oPrev.style.background = 'orange';
JS-firstChild,firstElementChild,lastChild,firstElementChild,nextSibling,nextElementSibling的更多相关文章
- js firstChild 、nextSibling、lastChild、previousSibling、parentNode
nextSibling下一个兄弟节点 previousSibling上一个兄弟 parentNode父亲节点 <select><option value="zs" ...
- nodeValue、firstChild和lastChild属性
nodeValue属性如果想改变一个文本节点的值,那就使用DOM提供的nodeValue属性,他用来得到(和设置)一个节点的值:node.nodeValue但是有个细节必须注意:在用nodeValue ...
- 选择器:first-child与:last-child失效的解决方法
作为还在努力练习的代码小白来说,有时类名或者ID名太多很容易就会搞混,为此,在练习中会想着借用多样的选择器来设置而不是每一个标签都设一个类名(Id名),在此次练习中使用选择器:first-child与 ...
- CSS nth-child、first-child、last-child、nth-of-type、first-of-type和last-of-type选择器使用
以下示例主要讲解nth-child.first-child.last-child.nth-of-type.first-of-type和last-of-type使用. 示例代码: <!DOCTYP ...
- js node.children与node.childNodes与node.firstChild,node,lastChild之间的关系
博客搬迁,给你带来的不便,敬请谅解! http://www.suanliutudousi.com/2017/11/06/js-node-children%e4%b8%8enode-childnodes ...
- jQuery中的子(后代)元素过滤选择器(四、六):nth-child()、first-child、last-child、only-child
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...
- CSS3中first-child、last-child、nth-child、nth-last-child
1.单独指定第一个子元素.最后一个子元素的样式 <style type="text/css"> li:first-child{ background:yellow; } ...
- CSS选取指定位置标签first-child、last-child、nth-child
1.first-child 选择列表中的第一个标签. 2.last-child 选择列表中的最后一个标签 3.nth-child(n) 选择列表中的第n个标签 4.nth-child(2n) 选择列表 ...
- first-child和last-child选择器 nth-child(n)第几个元素 nth-last-child(n)倒数第几个元素
:first-child 和 :last-child 分别表示父元素中第一个 或者 最后一个 子元素设置样式,如上图
随机推荐
- PDF的信息表达原理及特点分析
一.PDF概述 PDF(Portable Document Format)是一种结构化的文档格式.它由美国著名排版与图像处理软件Adobe公司于1993年首次发布(1.0版),并于同年推出了其相应的支 ...
- VFP正则表达式判断是否是手机号码/电子邮件
正则表达式,可以理解为字符匹配或搜索技术 ,重要的是Pattern属性的写法. *--判断是否是手机号码Function isMobiPhoneLparameters cStroRegExp=Newo ...
- JS中this的指向问题
JS中this的定义:this对象是在运行时基于函数的执行环境绑定的(通俗点来说就是:this代表当前函数属于哪个对象). this一般情况下都代表的是global对象,在浏览器中就是window对象 ...
- npm 换源
npm config set registry https://registry.npm.taobao.org
- 配置 samba 实现文件共享
用于实现文件共享 netstat -apn|grep smb 可以按到 smb服务,需要开启139 .445端口号 需要在防火墙添加如下规则vi /etc/sysconfig/iptables -A ...
- Shell学习笔记 - 环境变量配置文件(转)
一.source命令 功能:在当前bash环境下读取并执行配置文件中的命令 1. 命令格式 source 配置文件 或 . 配置文件 2. 命令示例 [root@localhost ~]# sou ...
- 十二 .ocBlock
NSProxy是一个不继承NSObject的根类(尽管它遵守NSObject协议),调用[[NSProxy alloc]init]将会产生一个运行异常. 所幸,oc引入被称为“块代码”的第一级函数的概 ...
- LLVM example for main
#include "llvm/IR/CallSite.h" #include "llvm/IR/Instruction.h" #include "ll ...
- python出输出字符串方式:
python出输出字符串方式: >>> who='knights' >>> what='NI' >>> print ('we are the',w ...
- ORA-20000:ORU-10027:buffer overflow,limit of 2000 bytes.
ORA-20000:ORU-10027:buffer overflow,limit of 2000 bytes. 这是因为在过程中用到了dbms_output.put_line()在服务器端输出信 ...