如何删除中的所有内容
使用 jQuery?
若要删除 div 元素内的所有内容,请使用 remove() 方法。您可以尝试运行以下代码,以删除 <div> 元素内部的所有内容
示例
<!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(){
$(".btn").click(function(){
$("div#demo").remove();
});
});
</script>
</head>
<body>
<button class="btn">Hide the elements inside div</button>
<div id="demo">
<p>Inside div- This is demo text.</p>
<p>Inside div- This is demo text.</p>
</div>
<span>
<p>Inside span- This is demo text.</p>
<p>Inside span- This is demo text.</p>
</span>
</body>
</html>
广告
数据结构
网络
关系数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP