理解Jquery的first-of-type选择器
来源:互联网 发布:高校教学软件租赁 编辑:程序博客网 时间:2024/05/19 18:15
理解Jquery的first-of-type选择器
$(“p:first-of-type”)
选取属于其父元素的第一个 p 元素的每个p元素:
实例代码
<!DOCTYPE html><html> <head> <meta charset="utf-8"> <title>first-child选择器</title> <script src="../../jquery.min.js"> </script> <script> $(document).ready(function(){ $("p:first-of-type").css("background-color","red"); }); </script> </head> <body> <p>the first paragraph in body</p> <div style="border:1px solid;"> <p>The first paragraph in div.</p> <p>the last paragraph in div.</p> </div><br> <div style="border:1px solid;"> <span>This is a span element.</span> <p>The first paragraph in another div.</p> <p>The last paragraph in another div.</p> </div> </body></html>
dom树
通俗解释
首先定位到当前文档中的所有p元素的父级元素,然后在每个父级元素下,找到第一个为p类型的元素,然后再给其加上背影效果,特别要区分开
(“p:first−child”)。 (“p:last-of-type”),刚好和此相反。
扩展
$(“p:nth-of-type(n)”)
属于其父元素的第n个 p 元素的所有 p 元素$(“p:nth-last-of-type(n)”)
选取属于其父元素的第三个 p 元素的每个 p 元素,从最后一个子元素开始计数
0 0
- 理解Jquery的first-of-type选择器
- jQuery 选择器 first-child和first-of-type、 last-child和last-of-type的区别
- first-of-type选择器
- 【CSS3】first-of-type选择器
- css选择器:first-of-type
- 理解Jquery的first-child选择器
- jQuery选择器中last-of-type和first-of-type效果案例
- 【CSS3】---first-of-type选择器+nth-of-type(n)选择器
- css选择器中:first-child与:first-of-type的区别///CSS3伪类nth-of-type(n)用法详解
- css选择器中:first-child与:first-of-type的区别
- CSS选择器中first-child和first-of-type的区别
- css选择器中:first-child与:first-of-type的区别
- css选择器中:first-child与:first-of-type的区别
- 在css选择器中:first-child与:first-of-type的用法
- css选择器中:first-child与:first-of-type的区别
- CSS选择器 first-child 、first-of-type 和 nth-of-type()
- first-child first-of-type last-child last-of-type 伪类选择器总结
- jQuery中的小知识:first-child和first-of-type的区别
- com.google.code.findbugs引起的错误
- Linphone callState 电话状态的监听状态(二)
- nginx配置http2无效不起作用
- 安装完成服务器进行优化
- css-position:absolute时如何居中
- 理解Jquery的first-of-type选择器
- 2017LinuxPHP+Mysql+nginx最详尽配置学习手册包括优化
- windows网络模型
- 冒泡排序和改进
- Ubuntu调教手册(软件安装sogou,chrome等)
- git commit message 工程实践
- 跨站请求伪造CSRF防护方法
- C#中的结构体要使用new来实例化吗?
- codevs1073 家族 并查集