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 分别表示父元素中第一个 或者 最后一个 子元素设置样式,如上图
随机推荐
- HTML5 CANVAS画图 beginPath和closePath
beginPath这个canvas函数我很早就讲过了,他的作用很简单,就是开始一段新路径,我们先来看下面的一小段代码: var ctx = document.getElementById('cvs') ...
- DragSelectRecyclerView 长按滑动多选图像android特效
高仿Google相册多选效果,长按某一item后然后滑动选择到任意item,效果很不错,适合相册页面多选部分效果. 本例子主要是自定义DragSelectRecyclerView通过如下展示gridv ...
- ORACLE连接SQLSERVER
一.实验(实验成功) 1.实验目标:ORACLE连接SQLSERVER以及查询数据 2.搭建的环境: oracle 9i 9.0.2.0.1 地址:192.168.40.139 sql2000 的数据 ...
- spring mvc学习笔记一:hello world
下面是创建springmvc简单案例的步骤: 项目的目录结构如下: 此案例使用maven构建. 第一步:创建动态web工程,然后项目->configure->convert to mave ...
- Windows服务一:新建Windows服务、安装、卸载服务
Windows 服务(即,以前的 NT 服务)使您能够创建在它们自己的 Windows 会话中可长时间运行的可执行应用程序.这些服务可以在计算机启动时自动启动,可以暂停和重新启动而且不显示任何用户界面 ...
- ORACLE 获取程序当前位置的方法
FUNCTION f_Get_Program_Position RETURN VARCHAR2 IS l_Owner ); l_Name ); l_Lineno NUMBER; l_Type ); B ...
- SecureCRT和SecureFx设置中文乱码
SecureCRT和SecureFx设置中文乱码 SecureCRT和SecureFx连接服务器时中文显示乱码,找了好多资料好久都没整出来,后来整出来了,因此把个人的解决办法提供出来,已变帮助更多的人 ...
- spring mvc 第一天【注解实现springmvc的基本配置】
创建pojo,添加标识类的注解@Controller,亦可添加该Handler的命名空间:设置类的@RequestMapping(value="/hr") 该类中的方法(Handl ...
- 理解View与Model分离
说实话MV*架构中,Model与View分离已经听人谈了好久,但是以前始终没太弄懂什么意思,最近终于稍微懂了一些,虽然不一定很对,暂且先记录下来. 谈Model与View分离,首先要弄懂页面在前端渲染 ...
- Android开源框架——Volley
Volley 是 Google 在 2013 I/O 大会上推出的 Android 异步网络请求框架和图片加载框架.特别适合数据量小,通信频繁的网络操作.Volley 主要是通过两种 Diapatch ...