Jquery: powerful selectors
Jquery selectors are divided into basic selectors, hierarchical selectors, filter selectors and form selectors. These four selectors are introduced one by one below.
1. Basic selectors
Most of them are basic selectors. Basic selectors include id selector, class selector, label selector, compound selector and "*" selector.
$("#id") Selects all elements whose attribute id is equal to "id".
$(".class_1") Selects all elements whose attribute class is "class_1".
$("p") selects all
elements.
$("div,span,p.myClass") selects a group of elements of all
tags whose attribute class is "myClass".
$("*") selects all elements.
2. Hierarchical Selector
If you want to obtain specific elements based on the hierarchical relationship between elements, you can choose to use a hierarchical selector.
$("div p") selects all
elements in
$("div>p") selects all tags in
child elements.
$(".class_1+div") Selects the next
$(".class_1").next("div") The effect is the same as above.
$(".class_1~div") selects all
$(".class_1").nextAll("div") The effect is the same as above.
$(".class_1").siblings("div") The difference from the above two selectors is that this selector has no distinction between before and after. It selects all
3. Filter selectors
Filter selectors all start with a colon (:). Filter selectors can be divided into basic filtering, content filtering, visibility filtering, attribute filtering, sub-element filtering and form object attribute filtering selectors. .
1. Basic filter selector
$("div:first") selects the first
$("div:last") selects the last
$("input:not(.class_1)") Selects elements whose attribute class is not "class_1".
$("input:even") selects the element whose index is even.
$("input:odd") selects the element whose index is odd.
$("input:eq(1)") Selects the element with index equal to 1.
$("input:gt(1)") Selects elements with index greater than 1. (Note: greater than 1, not including 1)
$("input:lt(1)") Selects elements with index less than 1. (Note: less than 1, not including 1)
$(":header") selects all
, , ... in the web page.
... in the web page.
$("div:animated") selects the
$(":focus") selects the currently focused element.
2. Content filter selector
$("div:contains('I')") Selects the
$("div:empty") selects
$("div:has(p)") selects the
element.
$("div:parent") selects
3. Visibility filter selector
$(":hidden") selects all invisible elements, $("input:hidden") selects all invisible elements.
$("div:visible") selects all visible
4. Attribute filter selector
$("div[id]") selects the
$("div[title=text]") Selects the
$("div[title!=text]") Selects
$("div[title^=text]") Selects the
$("div[title$=text]") selects the
$("div[title*=text]") Selects the
$('div[title|="text"]') Selects the
$('div[title~="text"]') Selects elements whose attribute title contains the character "text" in the space-separated value.
$("div[id][title$='text']") Selects the
5. Child element filter selector
$("div.one:nth-child(2)") Selects the second child element under the
$("div.one:first-child(2)") Selects the first child element under the
$("div.one:last-child(2)") Selects the last child element under the
$("div.one:first-child(2)") If there is only one child element under the
6. Form object attribute filter selector
$("#form1 input:enabled") selects the elements available in the form.
$("#form1 input:disabled") selects the elements that are not available in the form.
$("input:checked") Select the selected check box.
$("select:selected") Select the selected item in the drop-down box.
(Note: Set the attribute disabled in the element to "disabled" to make this element unavailable)
4. Form selector
$(":input") selects all ,
$(":text") selects all single-line text boxes.
$(":password") selects all password boxes.
$(":radio") Select all radio boxes.
$(":checkbox") Select all checkboxes.
$(":image") selects all image buttons.
$(":reset") selects all reset buttons.
$(":button") selects all buttons.
$(":file") selects all upload controls.
$(":hidden") selects all invisible elements.
5. Some precautions in the selector
1. Some attribute values contain special characters
For example:
2. The selector contains spaces
Comparison between $('.class_1:hidden') and $('.class_1:hidden').
$('.class_1 :hidden') gets the hidden elements contained in the element whose attribute class is class_1.
$('.class_1:hidden') gets the element whose attribute class is class_1.
For more Jquery: Powerful Selector related articles, please pay attention to 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

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

How to merge array elements with the same ID into one object in JavaScript? When processing data, we often encounter the need to have the same ID...

Learning JavaScript is not difficult, but it is challenging. 1) Understand basic concepts such as variables, data types, functions, etc. 2) Master asynchronous programming and implement it through event loops. 3) Use DOM operations and Promise to handle asynchronous requests. 4) Avoid common mistakes and use debugging techniques. 5) Optimize performance and follow best practices.

Discussion on the realization of parallax scrolling and element animation effects in this article will explore how to achieve similar to Shiseido official website (https://www.shiseido.co.jp/sb/wonderland/)...

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

In-depth discussion of the root causes of the difference in console.log output. This article will analyze the differences in the output results of console.log function in a piece of code and explain the reasons behind it. �...
