This time I will bring you a summary of the usage of JQuery $(), what are the precautions when using JQuery $(), the following is a practical case, let's take a look.
Usage of JQuery $(): There are three main types, taking expressions, taking elements, and taking functions.
1, Tag selector$('p'), Class selector$('.myClass'), id selector $('#myId') is relatively simple, not much to say. But there is one thing - there is a difference between $('p>ul') and $('p ul').
$('p>ul') is the direct descendant of
- ; and $('p ul') searches for
- child nodes with the id "sId". Even if the descendants of this
- still have
- , they are not the ones it selects. The scope of the search (the DOM object found is only the DOM object of its own level.). And $('#sId li:not(.horizontal)') means that all the descendants of li in the class name "sId" do not have all elements of the horizontal class. ——not() here is a negation
pseudo class.
What is returned here is a jQurey object, an array object. The length of this jQuery object can be obtained with .length().
2. What is in ] is the attribute of the element; it is a
attribute selector
There is no @ in [], which means that what is in [] is the descendant of the element. $('ul li') and $('ul[li]') both return a jQuery array, but their meanings are exactly the opposite. The former is to find all the descendants of - under
- , while the latter is to find the
- .
In XPath, if you want to find an attribute "starting with...", use ^=. If you want to find an input element whose name attribute starts with mail, use
$('input[@name^ ="mail"]')
To find an attribute that "ends with...", use $=
To find an attribute that has "no beginning or end", use *=
3, Selectors that do not belong to the above-mentioned CSS and XPath are custom selectors, represented by ":". The ones used here are: first, :last, :parent, :hidden, :visible, :odd, :even , :not('xxx'), ":eq(0)" (starts at 0), :nth(n), :gt(0), :lt(0), :contains("xxx")
For example: $('tr:not([th]):even') means the even-numbered items of all the descendants of theelement that do not include the descendants of
4. There are a few more, simple No explanation$('th').parent()—— $('td:contains("Henry")').prev()——内容包含有"Henry"的<td>的上一个节点 $('td:contains("Henry")').next()——内容包含有"Henry"的<td>的下一个节点 $('td:contains("Henry")').siblings()——内容包含有"Henry"的<td>的所有兄弟节点
There is another one, which is end(). This method must be used when a DOM node performs a certain action and wants to perform a similar action on the node related to it. , end() is used here. After using the end() method, what is returned is the parent node of the node that performs the action. For example $(...).parent().find(...).addClass().end()The node that performs the action here is find(...), which is an array Object, the action it takes is "addClass()", and then end() is used. At this time, the returned stuff points to the node pointed to by parent(), that is, the "addClass()" action is performed. The parent node of that array object.
5. To access DOM elements directly, you can use the get(0) method, such as
$('#myelement').get(0), which can also be abbreviated to $('#myelement')[0]
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!Recommended reading:
How to operate the width and height attributes of the page, visual area, screen, etc.How to use Web Storage storage
- array whose descendants are
- .
- among all descendants of
.
So, $('#sId>li') selects all
The above is the detailed content of JQuery $() usage summary. For more information, please follow other related articles on the PHP Chinese website!

The core features of HTML5 include semantic tags, multimedia support, offline storage and local storage, and form enhancement. 1. Semantic tags such as, etc. to improve code readability and SEO effect. 2. Simplify multimedia embedding with labels. 3. Offline storage and local storage such as ApplicationCache and LocalStorage support network-free operation and data storage. 4. Form enhancement introduces new input types and verification properties to simplify processing and verification.

H5 provides a variety of new features and functions, greatly enhancing the capabilities of front-end development. 1. Multimedia support: embed media through and elements, no plug-ins are required. 2. Canvas: Use elements to dynamically render 2D graphics and animations. 3. Local storage: implement persistent data storage through localStorage and sessionStorage to improve user experience.

H5 and HTML5 are different concepts: HTML5 is a version of HTML, containing new elements and APIs; H5 is a mobile application development framework based on HTML5. HTML5 parses and renders code through the browser, while H5 applications need to run containers and interact with native code through JavaScript.

Key elements of HTML5 include,,,,,, etc., which are used to build modern web pages. 1. Define the head content, 2. Used to navigate the link, 3. Represent the content of independent articles, 4. Organize the page content, 5. Display the sidebar content, 6. Define the footer, these elements enhance the structure and functionality of the web page.

There is no difference between HTML5 and H5, which is the abbreviation of HTML5. 1.HTML5 is the fifth version of HTML, which enhances the multimedia and interactive functions of web pages. 2.H5 is often used to refer to HTML5-based mobile web pages or applications, and is suitable for various mobile devices.

HTML5 is the latest version of the Hypertext Markup Language, standardized by W3C. HTML5 introduces new semantic tags, multimedia support and form enhancements, improving web structure, user experience and SEO effects. HTML5 introduces new semantic tags, such as, ,, etc., to make the web page structure clearer and the SEO effect better. HTML5 supports multimedia elements and no third-party plug-ins are required, improving user experience and loading speed. HTML5 enhances form functions and introduces new input types such as, etc., which improves user experience and form verification efficiency.

How to write clean and efficient HTML5 code? The answer is to avoid common mistakes by semanticizing tags, structured code, performance optimization and avoiding common mistakes. 1. Use semantic tags such as, etc. to improve code readability and SEO effect. 2. Keep the code structured and readable, using appropriate indentation and comments. 3. Optimize performance by reducing unnecessary tags, using CDN and compressing code. 4. Avoid common mistakes, such as the tag not closed, and ensure the validity of the code.

H5 improves web user experience with multimedia support, offline storage and performance optimization. 1) Multimedia support: H5 and elements simplify development and improve user experience. 2) Offline storage: WebStorage and IndexedDB allow offline use to improve the experience. 3) Performance optimization: WebWorkers and elements optimize performance to reduce bandwidth consumption.


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

Atom editor mac version download
The most popular open source editor

Dreamweaver CS6
Visual web development tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!
