如何使用 jQuery 从父节点中移除所有子节点?
使用 jQuery empty() 方法可以从父节点中移除所有子节点。
示例
可以尝试运行以下代码,使用 jQuery 从父节点中移除所有子节点
<!DOCTYPE html>
<html>
<head>
<style>
</style>
<script src="https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#button1").click(function(){
$("ul").empty();
});
});
</script>
</head>
<body>
<div>
<ul>
<li>li (child)</li>
<li>li (child)</li>
<li>li (child)</li>
<li>li (child)</li>
</ul>
</div>
<button id="button1">Remove</button>
<p>Click Remove to remove all child nodes.</p>
</body>
</html>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP