Home  >  Article  >  Web Front-end  >  What is next in jquery?

What is next in jquery?

WBOY
WBOYOriginal
2022-05-10 15:11:432666browse

In jquery, next is a method used to return the sibling element after the selected element; this method can match the sibling elements immediately adjacent to each element in the element collection and retrieve the next sibling element that matches the selector. Sibling elements, and only returns one element, the syntax is "element object.next(selector)".

What is next in jquery?

The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.

What is next in jquery

next() method returns the next sibling element of the selected element.

Sibling elements are elements that share the same parent element.

Note: This method only returns one element.

DOM tree: This method traverses forward along the next sibling element of the DOM element.

Syntax

$(selector).next(filter)

Parameter Description

filter Optional. Specifies a selector expression that narrows the search to one sibling element.

next() Gets the immediately adjacent sibling elements of each element in the matching element set. If a selector is provided, retrieves the next sibling element that matches the selector.

The example is as follows:

<!DOCTYPE html>
<html>
<head>
  <script type="text/javascript" src="/jquery/jquery.js"></script>
</head>
<body>
  <p>Hello</p>
  <p class="selected">Hello Again</p>
  <div><span>And Again</span></div>
<script>
  $("p").next(".selected").css("background", "yellow");
</script>
</body>
</html>

Output result:

What is next in jquery?

Related video tutorial recommendation: jQuery video tutorial

The above is the detailed content of What is next in jquery?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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