Home > Web Front-end > JS Tutorial > jQuery performs the next traversal based on the current element_jquery

jQuery performs the next traversal based on the current element_jquery

WBOY
Release: 2016-05-16 16:47:41
Original
994 people have browsed it

If we have selected a group of elements through the jQuery method, how to proceed to the next step of traversal based on these selected elements?

For example, we selected the second li element in the following code by

$('li:eq(1)')

.

Copy code The code is as follows:



Based on this selected element, we can further traverse other elements

Next element

$('li: eq(1)').next()

Previous element

$('li:eq(1)').prev()

Parent element

$('li:eq(1)').parent()

All sibling elements

$('li:eq(1)').parent(). children()

All subsequent sibling elements

$('li:eq(1)').nextAll()

All preceding sibling elements

$('li:eq(1)').prevAll()

All the above traversal methods can use the end() method to cancel the operation.

Of course, you can also use parameters, such as

$('li:eq(1)').parent().children(':last')
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template