Home  >  Article  >  Web Front-end  >  How to hide all subordinate elements in jquery

How to hide all subordinate elements in jquery

青灯夜游
青灯夜游Original
2022-03-23 17:09:191411browse

Jquery method of hiding all subordinate elements: 1. Use the find() method to obtain all subordinate elements (including subsets of subsets); 2. Use the hide() method to hide the obtained elements, syntax "Specify element.find().hide();".

How to hide all subordinate elements in jquery

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

jquery hides all subordinate elements

Implementation ideas:

  • Use the find() method to Get all subordinate elements (including subsets of subsets)

  • Use the hide() method to hide the obtained elements

Implementation code:

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<script src="js/jquery-1.10.2.min.js"></script>
		<script>
			$(document).ready(function() {
				$("button").click(function() {
					$("div").find("*").hide();
				});
			});
		</script>
	</head>
	<body>

		<div style="border: 1px solid red;">
			<ul>
				<li>姓名:aa</li>
				<li>年龄:25</li>
				<li>爱好:
					<ul>
						<li>运动</li>
						<li>听音乐</li>
						<li>烹饪</li>
					</ul>
				</li>
			</ul>
		</div>
		<button>隐藏下级所有元素</button>
	</body>
</html>

How to hide all subordinate elements in jquery

[Recommended learning: jQuery video tutorial, web front-end development]

The above is the detailed content of How to hide all subordinate elements in jquery. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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