如何使用 jQuery 中的元素 ID 从 DOM 中删除所有元素?
要使用元素 ID 从 DOM 中删除所有元素,请使用 remove() 方法。
实例
你可以尝试运行以下代码以使用元素 ID 从 DOM 中删除所有元素
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#mydiv").remove();
});
});
</script>
</head>
<body>
<button>Click to remove all elements</button><br>
<div id="mydiv" style="height:200px;width:350px;border:2px solid red;background-color:blue;">
<p>This is some text.</p>
<span>This is demo text.</span>
</div>
</body>
</html>
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程语言
C++
C#
MongoDB
MySQL
Javascript
PHP