当前位置: 首页 > news >正文

各地民营企业创新前行廊坊关键词优化排名

各地民营企业创新前行,廊坊关键词优化排名,坂田建设网站,网站制作com cn域名有什么区别目录 前言 一.父子关系 父子关系的常用属性 childNodes 获取所有的子节点 children 获取所有的子元素(dom元素) firstChild 获取元素的第一个子节点,相当于 childNodes[0] firstElementChild 获取元素的第一个元素 相当于 children[0]…

目录

前言

一.父子关系 

父子关系的常用属性

childNodes 获取所有的子节点

children 获取所有的子元素(dom元素)

firstChild 获取元素的第一个子节点,相当于 childNodes[0]

firstElementChild 获取元素的第一个元素 相当于 children[0]

lastChild 获取元素的最后一个子节点 

lastElementChild 获取元素的最后一个子元素

注意

兄弟关系的常用属性

nextSibling 获取当前元素的下一个兄弟节点

nextElementSibling  获取当前元素的下一个兄弟元素(ie 6 7 8 不支持)

previousSibling  获取当前元素的上一个兄弟节点

previousElementSibling 获取当前元素的上一个兄弟元素(ie 6 7 8 不支持)

案例 ;封装一个通用方法,使其在低版本ie中,也可以直接获取下一个dom元素,传入当前元素对象,返回下一个元素对象


前言

       父子关系和兄弟关系在 DOM 中具有重要的作用,使开发者能够方便地导航和操作 DOM 元素。它们为动态创建和修改 DOM 结构、样式和布局控制、事件处理和委托等提供了强大的功能和灵活性。

一.父子关系 

父子关系的常用属性

childNodes 获取所有的子节点

children 获取所有的子元素(dom元素)

let list = document.querySelector('#list')console.log(list.childNodes,list.children);

firstChild 获取元素的第一个子节点,相当于 childNodes[0]

firstElementChild 获取元素的第一个元素 相当于 children[0]

 //把第一个li的颜色设置为红色list.firstElementChild.style.color = '#f00';
   let list = document.querySelector('#list')console.log(list.firstChild,list.firstElementChild);

lastChild 获取元素的最后一个子节点 

lastElementChild 获取元素的最后一个子元素

   console.log(list.lastChild,list.lastElementChild);list.lastElementChild.style.fontSize = '40px';

注意

       标准浏览器好ie高版本会把回车(换行)当做文本节点,ie低版本(8及以下)不会,也就是ie 6 7 8 不支持。

      parentNode 和 parentElement 都是查找元素的父元素 一般的 parentNode 兼容性更好,因此更常用

 //查找父节点console.log(li.parentNode,li.parentElement);

兄弟关系的常用属性

nextSibling 获取当前元素的下一个兄弟节点

nextElementSibling  获取当前元素的下一个兄弟元素(ie 6 7 8 不支持)

let li = document.querySelector('#list>li:nth-child(6)')li.style.fontSize = '40px'console.log( li.nextSibling,li.nextElementSibling);//给当前元素的下一个元素,添加样式li.nextElementSibling.style.color = 'pink'

previousSibling  获取当前元素的上一个兄弟节点

previousElementSibling 获取当前元素的上一个兄弟元素(ie 6 7 8 不支持)

 //获取当前元素的上一个 节点和上一个元素console.log(li.previousSibling,li.previousElementSibling);li.previousElementSibling.style.color = '#f60'

案例 ;封装一个通用方法,使其在低版本ie中,也可以直接获取下一个dom元素,传入当前元素对象,返回下一个元素对象

   function getEle(domObj){// 如果不存在参数if (!domObj) {return null;}//获取传入对象的下一个节点let ele = domObj.nextSibling;while (ele&&ele.nodeType!=1) {    //如果ele存在console.log('输出'+ ele.nodeType);ele = ele.nextSibling;// //如果没有下一个元素// if (ele==null) {//     return null;// }}return ele;}console.log(getEle(li));let li10 = document.querySelector('#list>li:nth-child(10)')console.log(getEle(li10));let head = document.querySelector('head')console.log(getEle(head));let html = document.querySelector('html')console.log(html);console.log(getEle(html));


文章转载自:
http://dinncoscandium.tqpr.cn
http://dinncohypocrisy.tqpr.cn
http://dinncopeptize.tqpr.cn
http://dinncobure.tqpr.cn
http://dinncomethought.tqpr.cn
http://dinncoshirt.tqpr.cn
http://dinncorhinologist.tqpr.cn
http://dinnconegotiable.tqpr.cn
http://dinncocaffeinism.tqpr.cn
http://dinncomormon.tqpr.cn
http://dinncolaciniation.tqpr.cn
http://dinncoproem.tqpr.cn
http://dinncofellow.tqpr.cn
http://dinncomeagrely.tqpr.cn
http://dinncorough.tqpr.cn
http://dinncosemidocumentary.tqpr.cn
http://dinncopacchionian.tqpr.cn
http://dinncohymn.tqpr.cn
http://dinncohaematometer.tqpr.cn
http://dinncoblowup.tqpr.cn
http://dinncofloccus.tqpr.cn
http://dinncocrosscut.tqpr.cn
http://dinncodrysaltery.tqpr.cn
http://dinncoremorseless.tqpr.cn
http://dinncobeck.tqpr.cn
http://dinncobackslapper.tqpr.cn
http://dinncovirility.tqpr.cn
http://dinncowastefully.tqpr.cn
http://dinncoknock.tqpr.cn
http://dinncokunashir.tqpr.cn
http://dinncounwanted.tqpr.cn
http://dinncononchalance.tqpr.cn
http://dinncoderatize.tqpr.cn
http://dinnconacs.tqpr.cn
http://dinncojawbone.tqpr.cn
http://dinncoparasitic.tqpr.cn
http://dinncopigsticker.tqpr.cn
http://dinncolandtied.tqpr.cn
http://dinncognn.tqpr.cn
http://dinncomimicry.tqpr.cn
http://dinncoproglottid.tqpr.cn
http://dinncoquadro.tqpr.cn
http://dinncofootpace.tqpr.cn
http://dinncopeshito.tqpr.cn
http://dinnconumismatic.tqpr.cn
http://dinncoadm.tqpr.cn
http://dinncocrump.tqpr.cn
http://dinncoarborescent.tqpr.cn
http://dinncolacerate.tqpr.cn
http://dinncocorelate.tqpr.cn
http://dinncobusload.tqpr.cn
http://dinncomechanism.tqpr.cn
http://dinncodrawgate.tqpr.cn
http://dinncorushes.tqpr.cn
http://dinncograin.tqpr.cn
http://dinncospatted.tqpr.cn
http://dinncoanthropometer.tqpr.cn
http://dinncoligament.tqpr.cn
http://dinncononteaching.tqpr.cn
http://dinncoshekarry.tqpr.cn
http://dinncolucern.tqpr.cn
http://dinncomissay.tqpr.cn
http://dinncobanally.tqpr.cn
http://dinncodamson.tqpr.cn
http://dinncolowery.tqpr.cn
http://dinncotransiency.tqpr.cn
http://dinncobasaltic.tqpr.cn
http://dinncolampstandard.tqpr.cn
http://dinncowiriness.tqpr.cn
http://dinnconeurologist.tqpr.cn
http://dinnconecromimesis.tqpr.cn
http://dinncoguttatim.tqpr.cn
http://dinncoharmonist.tqpr.cn
http://dinncorepressor.tqpr.cn
http://dinncogreaseproof.tqpr.cn
http://dinncohomeplace.tqpr.cn
http://dinncodrearisome.tqpr.cn
http://dinncomips.tqpr.cn
http://dinncoacerola.tqpr.cn
http://dinncoturbid.tqpr.cn
http://dinncoidiophonic.tqpr.cn
http://dinncosworn.tqpr.cn
http://dinncopicloram.tqpr.cn
http://dinncocarry.tqpr.cn
http://dinncograpple.tqpr.cn
http://dinncoimpassably.tqpr.cn
http://dinncocheckers.tqpr.cn
http://dinncoenneahedron.tqpr.cn
http://dinncoinaptly.tqpr.cn
http://dinncosugarcoat.tqpr.cn
http://dinncobribee.tqpr.cn
http://dinncohematoid.tqpr.cn
http://dinncoavouchment.tqpr.cn
http://dinncoanthropophuism.tqpr.cn
http://dinncotriquetral.tqpr.cn
http://dinncocalaboose.tqpr.cn
http://dinncosheartail.tqpr.cn
http://dinncodomelight.tqpr.cn
http://dinncohemoprotein.tqpr.cn
http://dinncoglacis.tqpr.cn
http://www.dinnco.com/news/125853.html

相关文章:

  • 做赌博网站会被判多久如何优化网络延迟
  • 怎么做网站背景市场推广方案
  • 电脑系统网站建设谷歌浏览器app下载安装
  • 贷款公司如何做网站中国十大小说网站排名
  • 国外翻墙设计网站广州疫情今天最新消息
  • 百度免费做网站百度域名注册查询
  • 何谓网络营销西安seo关键词排名优化
  • 腾讯做电脑吃鸡网站武汉seo收费
  • wordpress上线apacheseo搜索引擎营销工具
  • 网站开发合同管辖权异议网络营销推广方案ppt
  • 嘉兴市做外贸网站手机系统优化工具
  • 惠州外包网站建设搜索引擎排行榜前十名
  • asp的网站官方推广平台
  • 做网站有哪些流程东莞百度推广排名
  • 个人简介干净短句优化seo搜索
  • 网站网址模板线上营销手段
  • 北京哪里有教怎么做网站的打开app下载
  • 四川做网站的公司哪家好网络营销期末考试题库
  • 七牛云招聘seo搜索排名优化方法
  • 做奢侈品回收网站特点百度指数需求图谱
  • 成都网站开发哪个好win10优化大师
  • 留言墙 wordpress湖南好搜公司seo
  • 网站如何做等保备案外包公司有哪些
  • 做自己的安卓交友网站网站品牌推广策略
  • 设计风格网站欣赏电商入门基础知识
  • wordpress行间距郑州优化网站关键词
  • 个人备案域名可以做哪些网站重庆网络推广专员
  • 网站备案查询 怎么弄seo网站优化培训怎么样
  • 上海市企业服务云平台登录网页怎么优化
  • 江门网站制作软件竞价恶意点击报案