jquery next() method


  Translation results:

next

#英[nekst] 美[nɛkst]

adj. Immediately after; second to; close to; immediately adjacent

adv.Go on;then;behind;sequentially

n.next;next one

prep.Close;behind;next door to…

jquery next() methodsyntax

Function: next() obtains the sibling elements immediately adjacent to each element in the matching element set. If a selector is provided, retrieves the next sibling element that matches the selector.

Syntax: .next(selector)

Parameters:

Parameter Description
selector String value, containing the selector expression used to match elements.

Description: If given a jQuery object that represents a collection of DOM elements, the .next() method allows us to search for elements in the DOM tree followed by sibling elements and constructs a new jQuery object with the matching element. The method accepts an optional selector expression of the same type that I passed into the $() function. If the following sibling element matches the selector, it will remain in the newly constructed jQuery object; otherwise, it will be excluded.

jquery next() methodexample

<!DOCTYPE html>
<html>
<head>
  <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.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>
Run instance »

Click the "Run instance" button to view the online instance

Popular Recommendations

Home

Videos

Q&A