What are jquery's selectors?
jquery’s selectors include: 1. Basic selectors (ID, element, class selector, etc.); 2. Basic filtering selectors (:first, :last, :even, etc.); 3. Content filtering Selectors (:empty, :has(), :parent, etc.); 4. Visibility filter selectors; 5. Attribute filter selectors, etc.
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
Introduction to jQuery Selectors
jQuery selectors allow operations on groups of HTML elements or individual elements.
JQuery selectors "find" (or select) HTML elements based on the element's id, class, type, attributes, attribute values, etc. It is based on existing CSS selectors, in addition to some custom selectors.
All selectors in jQuery begin with a dollar sign: $().
1.Basic selector
$("#test") 选择id值为test的元素,id值是唯一的所以返回单个元素。 $("div") 选择所有的div标签元素,返回div元素数组 $(".myclass") 选择使用myclass类的css的所有元素 $("*") 选取所有元素。 $("#test,div,.myclass") 选取多个元素。
2.Hierarchical selector
$("div span") 选取<div>里的所有<span>元素 $("div >span") 选取<div>元素下元素名是<span>的子元素 $("#one +div") 选取id为one的元素的下一个<div>同辈元素 等同于$("#one").next("div") $("#one~div") 选取id为one的元素的元素后面的所有<div>同辈元素 等同于$("#one").nextAll("div") $("#one").siblings("div") 获取id为one的元素的所有<div>同辈元素(不管前后) $("#one").prev("div") 获取id为one的元素的前面紧邻的同辈<div>元素 所以 获取元素范围大小顺序依次为: $("#one").siblings("div")>$("#one~div")>$("#one +div") 或是 $("#one").siblings("div")>$("#one").nextAll("div")>$("#one").next("div")
3.Basic filter selection Filter
$("div:first") 选取所有<div>元素中第1个<div>元素 $("div:last") 选取所有<div>元素中最后一个<div>元素 $("input:not(.myClass)") 选取class不是myClass的<input>元素 $("input:even") 选取索引是偶数的<input>元素(索引从0开始) $("input:odd") 选取索引是基数的<input>元素(索引从0开始) $("input:eq(2)") 选取索引等于2的<input>元素 $("input:gt(4)") 选取索引大于4的<input>元素 $("input:lt(4)") 选取索引小于4的<input>元素 $(":header") 过滤掉所有标题元素,例如:h1、h2、h3等 $("div:animated") 选取正在执行动画的<div>元素 $(":focus") 选取当前获取焦点的元素
4. Content filter selector
$("div:contains('Name')") 选取所有<div>中含有'Name'文本的元素 $("div:empty") 选取不包含子元素(包括文本元素)的<div>空元素 $("div:has(p)") 选取所有含有<p>元素的<div>元素 $("div:parent") 选取拥有子元素的(包括文本元素)<div>元素
5. Visibility filter selector
$("div:hidden") 选取所有不可见的<div>元素 $("div:visible") 选取所有可见的<div>元素
6. Attribute filter selector
$("div[id]") 选取所有拥有属性id的元素 $("input[name='test']") 选取所有的name属性等于'test'的<input>元素 $("input[name!='test']") 选取所有的name属性不等于'test'的<input>元素 $("input[name^='news']") 选取所有的name属性以'news'开头的<input>元素 $("input[name$='news']") 选取所有的name属性以'news'结尾的<input>元素 $("input[name*='news']") 选取所有的name属性包含'news'的<input>元素 $("div[title|='en']") 选取属性title等于'en'或以'en'为前缀(该字符串后跟一个连字符'-')的<div>元素 $("div[title~='en']") 选取属性title用空格分隔的值中包含字符en的<div>元素 $("div[id][title$='test']") 选取拥有属性id,并且属性title以'test'结束的<div>元素
7. Sub-element filter selector
$("div .one:nth-child(2)") 选取class为'one'的<div>父元素下的第2个子元素 $("div span:first-child") 选取每个<div>中的第1个<span>元素 $("div span:last-child") 选取每个<div>中的最后一个<span>元素 $("div button:only-child") 在<div>中选取是唯一子元素的<button>元素
8. Form object attribute filter selector
$("#form1 :enabled") 选取id为'form1'的表单内所有可用元素 $("#form2 :disabled") 选取id为'form2'的表单内所有不可用元素 $("input :checked") 选取所有被选中的<input>元素 $("select option:selected") 选取所有的select 的子元素中被选中的元素
9. Form selector
$(":input") 选取所有<input>,<textarea>,<select> 和 <button>元素 $(":text") 选取所有的单行文本框 $(":password") 选取所有的密码框 $(":radio") 选取所有单的选框 $(":checkbox") 选取所有的多选框 $(":submit") 选取所有的提交按钮 $(":image") 选取所有的图像按钮 $(":reset") 选取所有的重置按钮 $(":button") 选取所有的按钮 $(":file") 选取所有的上传域 $(":hidden") 选取所有不可见元素
[Recommended learning: jQuery video tutorial, web front-end development video】
The above is the detailed content of What are jquery's selectors?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Detailed explanation of jQuery reference method: Quick start guide jQuery is a popular JavaScript library that is widely used in website development. It simplifies JavaScript programming and provides developers with rich functions and features. This article will introduce jQuery's reference method in detail and provide specific code examples to help readers get started quickly. Introducing jQuery First, we need to introduce the jQuery library into the HTML file. It can be introduced through a CDN link or downloaded

How to use PUT request method in jQuery? In jQuery, the method of sending a PUT request is similar to sending other types of requests, but you need to pay attention to some details and parameter settings. PUT requests are typically used to update resources, such as updating data in a database or updating files on the server. The following is a specific code example using the PUT request method in jQuery. First, make sure you include the jQuery library file, then you can send a PUT request via: $.ajax({u

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: <

Title: Use jQuery to modify the text content of all a tags. jQuery is a popular JavaScript library that is widely used to handle DOM operations. In web development, we often encounter the need to modify the text content of the link tag (a tag) on the page. This article will explain how to use jQuery to achieve this goal, and provide specific code examples. First, we need to introduce the jQuery library into the page. Add the following code in the HTML file:

How to remove the height attribute of an element with jQuery? In front-end development, we often encounter the need to manipulate the height attributes of elements. Sometimes, we may need to dynamically change the height of an element, and sometimes we need to remove the height attribute of an element. This article will introduce how to use jQuery to remove the height attribute of an element and provide specific code examples. Before using jQuery to operate the height attribute, we first need to understand the height attribute in CSS. The height attribute is used to set the height of an element

jQuery is a popular JavaScript library that is widely used to handle DOM manipulation and event handling in web pages. In jQuery, the eq() method is used to select elements at a specified index position. The specific usage and application scenarios are as follows. In jQuery, the eq() method selects the element at a specified index position. Index positions start counting from 0, i.e. the index of the first element is 0, the index of the second element is 1, and so on. The syntax of the eq() method is as follows: $("s

jQuery is a popular JavaScript library widely used in web development. During web development, it is often necessary to dynamically add new rows to tables through JavaScript. This article will introduce how to use jQuery to add new rows to a table, and provide specific code examples. First, we need to introduce the jQuery library into the HTML page. The jQuery library can be introduced in the tag through the following code:

How to tell if a jQuery element has a specific attribute? When using jQuery to operate DOM elements, you often encounter situations where you need to determine whether an element has a specific attribute. In this case, we can easily implement this function with the help of the methods provided by jQuery. The following will introduce two commonly used methods to determine whether a jQuery element has specific attributes, and attach specific code examples. Method 1: Use the attr() method and typeof operator // to determine whether the element has a specific attribute
