jquery empty()方法


empty() 方法从被选元素移除所有内容,包括所有文本和子节点。

$(selector).empty()


<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".btn1").click(function(){
  $("p").empty();
  });
});
</script>
</head>
<body>
<p style="200px;height:200px;background-color:yellow">This is a paragraph. <b>Bold</b> and <i>italic</i> text.</p>
<button class="btn1">删除 p 元素的内容</button>
</body>
</html>

 测试链接: http://www.w3school.com.cn/tiy/t.asp?f=jquery_manipulation_empty_style



原文地址:https://www.cnblogs.com/mr-wuxiansheng/p/6399301.html