欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-04-23 15:11:36
本文实例讲述了jquery使用empty()方法删除元素及其所有子元素的方法。分享给大家供大家参考。具体实现方法如下: &l...

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

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