Home > Web Front-end > JS Tutorial > Example of next method usage in jQuery_jquery

Example of next method usage in jQuery_jquery

WBOY
Release: 2016-05-16 16:02:31
Original
1294 people have browsed it

The example in this article describes the usage of the next method in jQuery. Share it with everyone for your reference. The specific analysis is as follows:

Here is a demonstration of the usage of next in jQuery, which can obtain an element set containing the immediately following sibling elements of each element in the matched element set.

This function only returns the immediately following sibling element, not all the following sibling elements.

Can be filtered 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的用法</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() 也可以 
});
</script>
</head>
<body>
<p>Hello</p><p class="selected">这里的内容将显示</p><div>
<span>点我测试</span>
</div>
<!--取得一个包含匹配的元素集合中每一个元素紧邻的后面同辈元素的元素集合。
这个函数只返回后面那个紧邻的同辈元素,而不是后面所有的同辈元素。
可以用一个可选的表达式进行筛选。 
-->
</body> 
</html>
Copy after login

I hope this article will be helpful to everyone’s jQuery programming.

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