Home > Article > Web Front-end > What is next in jquery?
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)".
The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.
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:
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!