English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Metodo per selezionare e percorrere funzioni HTML con jQuery

Con jQuery, è facile selezionare gli elementi HTML. Ma in alcuni casi, quando la struttura HTML è piuttosto complessa, estrarre gli elementi selezionati può diventare una cosa piuttosto complicata.

1、children

This function gets the direct children of a set of elements.

Pass a selection expression to children() to narrow down the selection results to the selected elements;

If children() does not accept any parameters, it will return all direct children; it does not return its grandchild elements.

2、filter

This function filters elements from a collection by passing a selection expression. Any element that does not match this expression will be removed from the selected collection.

3、not

On the contrary to filter, not() removes matching elements from the collection.

4、add

What if we want to add some elements to the collection? The add() function is just for this.

5、slice

Sometimes, we need to get a subset of the collection based on the position of the element in the collection. slice() is just for this.

The first parameter is the position of the first element starting from zero, which is included in the returned segment;

The second parameter is the index of the first element starting from zero. It is not included in the returned segment. If omitted, it will extend to the end of the set;

6、parent

The parent() function selects the direct parent of a series of elements.

7、parents

This is the plural form, parents() selects all ancestor elements of the set. What I mean is that all ancestor elements include the direct parent to the 'body' and 'html' elements. Therefore, it is best to narrow down the selection results by passing an expression.

8、siblings

This function selects all siblings of a set of elements, and passing an expression can filter the results.

9、prev & prevAll

The prev() function selects the previous sibling node. prevAll() selects a collection of all preceding sibling nodes.

10、next & nextAll

These functions work in the same way as prev and prevAll, but they select the next sibling.

This article using the method of selecting HTML traversal with JQuery is all the content shared by the editor, hoping to provide a reference for everyone, and also hope that everyone will support the tutorial.

Ti potrebbe interessare