在IE下是支持firstChild,lastChild,nextSibling,previousSibling 但是在FF下,由于它会把标签之间的空格当成文本节点,所以为了准确地找到相应的元素,会用 firstElementChild, lastElementChild, nextElementSibling, previousElementSibling 兼容的写法是这样的 var oFirst = oParent.firstElementChild||oParent.firstChild  …
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <ul id="ul1"> <li>0001</li> <li>0002</li> <…
<html> <head> <title>HTML示例</title> <style type="text/css"> </style> </head> <body> <ul id="ulid"> <li id="li1">qqqqq</li> <li id="li2">wwww<…
childNodes 在JavaScript中,使用childNodes属性可以返回一个数组,这个数组包含给定元素节点的全体子节点. firstChild firstChild 这句代码等价于 目标元素节点下的子元素节点数组[0]; 目标元素节点.childNodes[0] 这句代码等价于 目标元素节点.firstChild; lastChild lastChild 这句代码等价于 目标元素节点下的子元素节点数组[目标元素节点下的子元素节点数组.length-1] 目标元素节点.childNod…
一个兼容 node 与浏览器的模块写法 // test.js (function (root, factory) { if (typeof define === 'function' && define.amd) { // AMD define(factory); } else if (typeof exports === 'object') { // Node, CommonJS-like // es6 module , typescript var mo = factory(); mo…
nth-child:定义第几个元素或者是奇数或者是偶数,或者满足某个数字倍数的dom的样式 如 li:nth-child(3n),结果如下,li:nth-child(2)结果如下…
nextSibling下一个兄弟节点 previousSibling上一个兄弟 parentNode父亲节点 <select><option value="zs">中山</option><option value="gz">广州</option><option value="zh">深圳</option><option value="zh"…
我将这坨伪类分成三组,第一组:nth-child,nth-last-child,only-child第二组:nth-of-type,nth-last-of-type,第三组:first-of-tpye,last-of-type,第四组:first-child,last-child. ==1== nth-child定义是:其父级的第x个子元素.写法有两种: p :nth-child(x) p:nth-child(x) 第一种指的是p的第x个子元素,无需查找,明确指明父级,而子级无论是什么元素都将被…
结构性伪类选择器—first-child “:first-child”选择器表示的是选择父元素的第一个子元素的元素E.简单点理解就是选择元素中的第一个子元素,记住是子元素,而不是后代元素. 示例演示 通过“:first-child”选择器定位列表中的第一个列表项,并将序列号颜色变为红色. HTML代码: <ol> <li><a href="##">Link1</a></li> <li><a href=&quo…
DOM hierarchy pseudo-classes allow you to style specific elements based on where they fall in the hierarchy and what type of elements they are. You can also use :nth-child to target custom element patterns, like every other element. <!doctype html>…