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

Video Face Swap

Video Face Swap

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

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:

How do PHP functions return objects? How do PHP functions return objects? Apr 10, 2024 pm 03:18 PM

PHP functions can encapsulate data into a custom structure by returning an object using a return statement followed by an object instance. Syntax: functionget_object():object{}. This allows creating objects with custom properties and methods and processing data in the form of objects.

Astar staking principle, income dismantling, airdrop projects and strategies & operation nanny-level strategy Astar staking principle, income dismantling, airdrop projects and strategies & operation nanny-level strategy Jun 25, 2024 pm 07:09 PM

Table of Contents Astar Dapp Staking Principle Staking Revenue Dismantling of Potential Airdrop Projects: AlgemNeurolancheHealthreeAstar Degens DAOVeryLongSwap Staking Strategy & Operation "AstarDapp Staking" has been upgraded to the V3 version at the beginning of this year, and many adjustments have been made to the staking revenue rules. At present, the first staking cycle has ended, and the "voting" sub-cycle of the second staking cycle has just begun. To obtain the "extra reward" benefits, you need to grasp this critical stage (expected to last until June 26, with less than 5 days remaining). I will break down the Astar staking income in detail,

What should I pay attention to when a C++ function returns an object? What should I pay attention to when a C++ function returns an object? Apr 19, 2024 pm 12:15 PM

In C++, there are three points to note when a function returns an object: The life cycle of the object is managed by the caller to prevent memory leaks. Avoid dangling pointers and ensure the object remains valid after the function returns by dynamically allocating memory or returning the object itself. The compiler may optimize copy generation of the returned object to improve performance, but if the object is passed by value semantics, no copy generation is required.

See all articles