Detailed explanation of common selectors in jQuery
This article mainly introduces the relevant information of jQuery commonly used selectors in detail. It has certain reference value. Interested friends can refer to it. I hope it can help everyone.
This article shares the specific code of jQuery commonly used selectors for your reference. The specific content is as follows
1. jQuery: (must be marked when using jQuery The version number we use)
It is a class library that uses native JS to encapsulate commonly used methods (solve browser compatibility issues)
2. jQuery The provided method
selector
obtains the specified element/element collection in the page by passing the content of the corresponding rule (ID, tag name, style class name...)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <p id='p1'> <p> <span></span> <span></span> <span></span> </p> <p></p> <p id='p3'></p> <ul> <li></li> <li></li> <li></li> </ul> </p> <script> //原生JS获取到的结果属于元素对象/元素集合/节点集合...他们可以使用浏览器为其提供的那些天生自带的属性和方法 //原生的JS对象不能直接的使用jQuery中提供的属性和方法 var op = document.getElementById('p1') op.clientWidth op.getAttribute //jq获取到的结果是一个jQuery对象,可以使用jQuery里面提供的属性和方法,但是不能直接的使用浏览器内置的属性和方法 var $op = jQuery("#p1")//$("#p1") $op.innerWidth(); $op.attr //关于原生JS对象和jQuery对象之间的转换 //1)、原生的转变成jQuery:$(原生JS对象) $(op) //2)、jQuery转化成原生:直接通过索引获取对应的元素对象即可 $op[0] $op.get(0)//<==>$op[0]都是通过索引来获取指定位置的元素(JS原生对象) //更多的jQuery选择器 $('#p1') $('p') $('.w100') $('*') $('#p1,p,.w100')//把每一个选择器获取到的jQuery对象最后融合在一起,最后一起获取到 $('#p1 li')//在子子孙孙级中进行查找 $('#p1>li')//在子级中进行查找 $('#p3+')//获取它的下一个弟弟 $('#p3+ul')//获取它的下一个弟弟并且标签名是ul的 $('#p3~')//获取它的所有的弟弟元素 $('#p3~ul')//获取它的所有的弟弟元素并且标签名为ul的 $('#p1>p:not(.w100)')//#p1下的所有子集p样式类名不包含w100的 $('#p1>p:eq(0)')//通过索引获取到集合中的某一个,但是获取到的结果依然是一个jQuery对象(而get方法也是通过索引获取,但是获取到的是一个JS原生对象) $('#p1>p:gt(1)')//大于索引1的(不包含索引1的) $('#p1>p:lt(1)')//小于索引1的(不包含索引1的) $('#p1 li:contains("我")')//获取所有的li内容包含“我” 的 $('#p1 p:has(ul)')//在所有的p中包含ul的 $('#p1>*:nth-child(1)')//获取所有的子元素的第一个 $('#p1>*:eq(1)')//获取所有的子元素的第二个(索引为1) </script> </body> </html>
Related recommendations:
Detailed explanation of how to handle special symbols in jQuery selectors
jQuery UI date picker Datepicker detailed explanation
Example detailed explanation jQuery form object attribute filter selector
The above is the detailed content of Detailed explanation of common selectors in jQuery. For more information, please follow other related articles on the PHP Chinese website!

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Zend Studio 13.0.1
Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download
The most popular open source editor