如何刪除中的所有內容
使用 jQuery?
若要刪除 div 元素內的所有內容,請使用 remove() 方法。您可以嘗試執行以下程式碼,以刪除 <div> 元素內部的所有內容
示例
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/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