Home > Web Front-end > JS Tutorial > body text

jquery selector introduction

一个新手
Release: 2017-09-25 09:42:01
Original
1466 people have browsed it

1.css selector general

1)标签选择器,以文档元素作为选择器
2)ID选择器,以ID标识符作为选择器;
3)类选择器,class
4)并集选择器,p,img,ul
5)后代选择器,#id ul li
6 )通配选择器 ,*{};
7)子代选择器,ul>li;
8)临近选择器,E+F;
9)交集选择器,p.class;
Copy after login

2.jquery selector

*(Important) Filter selector:

children(selector), $("ul").children("li"),相当于子代选择器,$("ul>li")选取ul中所有的子代li元素;集合元素
find(selector), $("ul").finde("li"),相当于后代选择器,$("ul li")选取ul中所有的后代li元素,后面的参数必传一般不用;集合元素
siblings(selector), $("#first").siblings("li“);选取兄弟节点的所有li,不包括自己;集合元素
parent(), $("#first").parent(),选取父元素节点,因为父元素节点只有一个所以不写;单个
parents(). $("#first").parents(),选取父元素节点上的元素,链式;父元素的父元素的父元素的所有;集合元素
eq(index);$(”li“).eq(2);相当于$("li:eq(2)"),index索引从0开始;单个
next(),$("li").next(),获取下一个兄弟元素;单个
prev(),$("li").next(),获取下一个兄弟元素;单个
Copy after login

*#Filter selector: both Colon

Basic selector, content filtering, visibility filtering, attribute filtering, child element filtering and form object attribute filtering attribute selector

a.Basic filtering selector

:first 选择第一个元素,$("p:first")选取所有<p>元素第一个;单个
:last 选取最后一个元素,$("p:last")选取所有<p>元素的最后一个p;单个
:not(selector) 去除所有与给定选择器相匹配的元素,$("input:not(.myClass)")选取class中不是不是myClass的<input>元素;集合元素
:even 选取索引是偶数的,索引从0开始,集合元素;
:odd 选取索引是奇数的,索引从0开始,集合元素;
:eq(index) 选取索引等于index的元素, $("input:eq(1)")选取索引是1的<input>元素; 单个
:gt(index) 选取索引大于index的元素, $("input:gt(1)")选取索引大于1的Input元素,不包括1;集合元素
:lt(index)选取索引小于index的元素,$("input:lt(1)")选取索引小于1的input元素,不包括1,集合元素
:header选取所有标题元素,$(":header")选取网页中所有的<h1><h2>....
:annimated选取当前正在执行动画的所有元素,$("p:animated")选取正在执行动画的p元素
Copy after login

The above is the detailed content of jquery selector introduction. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!