jQuery使用empty()方法删除元素及其所有子元素的方

编程学习 2021-07-04 21:47www.dzhlxh.cn编程入门
这篇文章主要介绍了jQuery使用empty()方法删除元素及其所有子元素的方法,涉及jQuery操作元素的技巧,具有一定参考借鉴价值,需要的朋友可以参考下

本文实例讲述了jQuery使用empty()方法删除元素及其所有子元素的方法。分享给大家供大家参考。具体实现方法如下:

<!DOCTYPE html>
<html>
<head>
<script src="js/jquery.min.js">
</script>
<script>
$(document).ready(function(){
 $("button").click(function(){
  $("#div1").empty();
 });
});
</script>
</head>
<body>
<div id="div1" style="height:100px;width:300px;border:1px solid black;background-color:yellow;">
This is some text in the div.
<p>This is a paragraph in the div.</p>
<p>This is another paragraph in the div.</p>
</div>
<br>
<button>Empty the div element</button>
</body>
</html>

希望本文所述对大家的jQuery程序设计有所帮助。

Copyright © 2016-2025 www.dzhlxh.cn 金源码 版权所有 Power by

网站模板下载|网络推广|微博营销|seo优化|视频营销|网络营销|微信营销|网站建设|织梦模板|小程序模板