and next in jQuery method nextAll

Get next and there's a method call tag peers behind the caller () and nextAll () in jQuery two, that the difference between the two, next () is to obtain the first tag with the caller after the peer label, nextAll () method is to get behind the caller with all the labels peers.

The following is a code sample:

First, using the acquired input selector id tag named sex and then calls next () method, obtaining a label on the back of the first label sex;

The call tag and then use nextAll () method, with all the labels acquiring peers, and using each loop in the array to print all objects behind Sex, results are as follows:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script src="js/jquery-3.3.1.js"></script>
	</head>
	<body>
		<form>
			<input />
			<input type="password" />
			<input id="sex" type="radio" value="0"/>男<input type="radio" value="1"/>女
			<input type="submit" value="提交"/>
		</form>
		
		<script>
			var e = $("#sex").next()[0];
			console.log(e);
			
			
			$("#sex").nextAll().each(function(){
				console.log(this);
			})
		</script>
	</body>
</html>

Published 99 original articles · won praise 93 · views 5221

Guess you like

Origin blog.csdn.net/DangerousMc/article/details/102991216