Home Web Front-end JS Tutorial Array-like operations in jQuery objects_jquery

Array-like operations in jQuery objects_jquery

May 16, 2016 pm 06:53 PM
jquery object operate

Look at what available methods our jQuery provides us with:
Size(): Obviously, it should return the number of elements in the packed set, such as $('a').size() Indicates the number of link elements;
Get(index): When index is not specified, all elements in the packaging set will be taken by default and returned in the form of an array in js. If index is specified, the subscript corresponding to index will be returned. Element, such as $('img[title]').get(0) returns the first img element containing the attribute title, which is also equivalent to $('img[title]')[0];
index (elem): Returns the subscript of the element elem in the packaging set, if the element is not found, returns -1;
 add(String|elem|Array): Adds the element in the parameter to the packaging set, if the parameter is jQuery selector, then all matching objects will be added to the collection. If it is an html element, the element array obtained through the clean method will be added to the collection. If it is a dom element or an array of dom elements, then it will be added directly to the collection. ; note that what is returned is the added package set; for example, $('img[alt]','img[title]') is equivalent to $('img[alt]').add('img[title]' ) that returns the img element containing the alt attribute or the img element containing the title attribute;
Not (String|elem|Array): Delete the elements that meet the parameter conditions in the packaging set. Note that the parameter can only be a filter expression. That is, expressions starting with "[" or ":", such as $('img[title]').not('title*=puy'), return img elements containing title attributes, and the title attributes of these elements are Contains puy text; returns the filtered packaging set;
Filter(String|function): If the incoming parameter is of String type, then the expression must also be a filtering expression, used to select from the packaging set Delete all elements that do not match the selector; if a function is passed in, then this function will be called for each element in the packaging set. If this function returns false, the element will be deleted from the packaging set. In the function, you can Use the this keyword to call the element that calls the method in the packaging set at that time; such as $('td').filter(function(){return this.innerHTML.match(/^"d $/)}) returns all td elements whose contents in td are numbers;
slice(begin,end): Create and return a new packaging set, which is a continuous part of the original packaging set, and the first of the new packaging set The first element is the element at the begin position of the original packaging set, and the last element is the element before the element at the end position. Of course, end does not need to be specified, then it will extend to the end of the original packaging set; such as $('*').slice (2,3) This statement selects all elements on the page, and then saves a new packaging set containing the third element of the original packaging set. Note that this $('*').get(2) is different, this returns the element , and the slice method returns a packaging set, thus having the operation of packaging set;
Childen(): Returns a new packaging set composed of all different sub-elements of the original packaging set element (excluding text nodes), such as $( 'div').children() returns a new packaging set composed of child elements under all div elements; if a parameter is specified, the parameter is also a filter expression;
Contents(): Returns the contents of the original packaging set element New packaging set (can contain text nodes); note that this method cannot accept parameters for filtering;
Next(): Returns a new packaging set composed of all unique next sibling elements of the original packaging set element; if parameters are specified , then this parameter is also a filter expression; for example, $('div#someDiv').next() returns a packaging set containing the next sibling element of the div element with the id someDiv; if a parameter is specified, then this parameter is also a filter expression Formula;
NextAll(): Returns a new packaging set that contains all subsequent siblings of the original packaging set element; such as $('div#someDiv').nextAll() returns a new packaging set that contains the subsequent siblings of the div element with the id of someDiv New packaging set; if a parameter is specified, then this parameter is also a filter expression;
parent(): Returns a new packaging set of the only direct parent element of all elements in the original packaging set; if a parameter is specified, then this parameter is also a filter expression Expression;
parents(): Returns a new packaging set of ancestor elements of all elements in the original packaging set; if a parameter is specified, the parameter is also a filter expression;
prev(): Returns the original packaging set elements A new wrapper set consisting of all unique previous sibling elements; if a parameter is specified, the parameter is also a filter expression;

prevAll(): Returns a new wrapper containing all previous sibling elements of the original wrapper set element Set; if a parameter is specified, then this parameter is also a filter expression;
siblings(): Returns a new packaging set composed of all unique sibling elements in the original packaging set element; if a parameter is specified, then this parameter is also Filter expression;
Find(String): Returns a new packaging set containing all elements in the original packaging set that match the passed selector expression, and the descendants of the elements in the original packaging set will also be passed into the new packaging set The packaging set;
contains(text): Returns a new packaging set composed of elements containing the text string passed in the text parameter;
is(String): If the packaging set contains String matching elements, then Returns true, otherwise returns false;
clone(copyHandle): If the parameter passed in is true, the event will be copied together, otherwise the event will not be copied and a new packaging set will be formed;
end(): In Called within the jQuery command chain to return to the previous packaging set;
andSelf(): merge the two recently generated packaging sets within the command chain;
The operations on packaging elements are summarized here, if something is wrong Please point it out for everyone’s reference and study.

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Linux Deploy operation steps and precautions Linux Deploy operation steps and precautions Mar 14, 2024 pm 03:03 PM

LinuxDeploy operating steps and precautions LinuxDeploy is a powerful tool that can help users quickly deploy various Linux distributions on Android devices, allowing users to experience a complete Linux system on their mobile devices. This article will introduce the operating steps and precautions of LinuxDeploy in detail, and provide specific code examples to help readers better use this tool. Operation steps: Install LinuxDeploy: First, install

Huawei Mate60 Pro screenshot operation steps sharing Huawei Mate60 Pro screenshot operation steps sharing Mar 23, 2024 am 11:15 AM

With the popularity of smartphones, the screenshot function has become one of the essential skills for daily use of mobile phones. As one of Huawei's flagship mobile phones, Huawei Mate60Pro's screenshot function has naturally attracted much attention from users. Today, we will share the screenshot operation steps of Huawei Mate60Pro mobile phone, so that everyone can take screenshots more conveniently. First of all, Huawei Mate60Pro mobile phone provides a variety of screenshot methods, and you can choose the method that suits you according to your personal habits. The following is a detailed introduction to several commonly used interceptions:

How to convert MySQL query result array to object? How to convert MySQL query result array to object? Apr 29, 2024 pm 01:09 PM

Here's how to convert a MySQL query result array into an object: Create an empty object array. Loop through the resulting array and create a new object for each row. Use a foreach loop to assign the key-value pairs of each row to the corresponding properties of the new object. Adds a new object to the object array. Close the database connection.

jQuery Tips: Quickly modify the text of all a tags on the page jQuery Tips: Quickly modify the text of all a tags on the page Feb 28, 2024 pm 09:06 PM

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: &lt

Use jQuery to modify the text content of all a tags Use jQuery to modify the text content of all a tags Feb 28, 2024 pm 05:42 PM

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:

PHP string manipulation: a practical way to effectively remove spaces PHP string manipulation: a practical way to effectively remove spaces Mar 24, 2024 am 11:45 AM

PHP String Operation: A Practical Method to Effectively Remove Spaces In PHP development, you often encounter situations where you need to remove spaces from a string. Removing spaces can make the string cleaner and facilitate subsequent data processing and display. This article will introduce several effective and practical methods for removing spaces, and attach specific code examples. Method 1: Use the PHP built-in function trim(). The PHP built-in function trim() can remove spaces at both ends of the string (including spaces, tabs, newlines, etc.). It is very convenient and easy to use.

What is the difference between arrays and objects in PHP? What is the difference between arrays and objects in PHP? Apr 29, 2024 pm 02:39 PM

In PHP, an array is an ordered sequence, and elements are accessed by index; an object is an entity with properties and methods, created through the new keyword. Array access is via index, object access is via properties/methods. Array values ​​are passed and object references are passed.

Discuz domain name modification operation guide Discuz domain name modification operation guide Mar 09, 2024 pm 04:36 PM

Discuz Domain Name Modification Operation Guide In the process of using the Discuz forum system, sometimes we need to modify the domain name of the forum. It may be because the domain name needs to be changed, or some domain name resolution problems need to be repaired. This article will introduce in detail how to modify the domain name in the Discuz forum system, and give some specific code examples. 1. Back up data Before performing any operation, we must back up the data to prevent data loss due to operational errors. In Discuz, you can use the background data backup

See all articles