Example of next method usage in jQuery

  • 2020-06-01 08:12:09
  • OfStack

This article illustrates the use of the next method in jQuery as an example. Share with you for your reference. The specific analysis is as follows:

This example demonstrates the use of next in jQuery to obtain a set of elements containing the next sibling of each of the matched set of elements.

This function returns only the next sibling, not all the next siblings.

You can filter with an optional expression


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
<title>next The use of the </title> 
<script type="text/javascript" src="/ajaxjs/jquery1.3.2.js"></script> 
<script type="text/javascript"> 
$(document).ready(function() {
  $("span").click(function(){alert($("p").next(".selected").html());})
  // $("p").next().html()  Can also be  
});
</script>
</head>
<body>
<p>Hello</p><p class="selected"> The content here will be displayed </p><div>
<span> Let me test </span>
</div>
<!-- achieve 1 Each of a set of elements containing matches 1 The set of elements that are immediately adjacent to each other. 
 This function returns only the next sibling, not all the next siblings. 
 You can use 1 Three optional expressions are filtered.  
-->
</body> 
</html>

I hope this article has been helpful to your jQuery programming.


Related articles: