jquery empty()方法

简介: empty() 方法从被选元素移除所有内容,包括所有文本和子节点。$(selector).empty()$(document).ready(function(){$(".btn1").

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="width: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



 

相关文章
|
2月前
|
JavaScript CDN
jQuery方法小记
jQuery方法小记
30 0
|
2月前
|
JavaScript
jQuery追加节点方法 和height方法与width方法
jQuery追加节点方法 和height方法与width方法
|
2月前
|
JavaScript 前端开发
调用jQuery的animate()方法无法移动的问题
调用jQuery的animate()方法无法移动的问题
|
2月前
|
JavaScript 前端开发 UED
jQuery 自动刷新页面但不闪烁的实现方法
jQuery 自动刷新页面但不闪烁的实现方法
|
7月前
|
JavaScript 前端开发
jQuery学习(十二)—jQuery中对象的查找方法总结
jQuery学习(十二)—jQuery中对象的查找方法总结
|
2月前
|
JavaScript Serverless
jquery attr()方法
jquery attr()方法
23 0
|
1月前
|
JSON JavaScript 前端开发
jQuery获取json文件的方法
jQuery获取json文件的方法
20 2
|
1月前
|
JavaScript 程序员
老程序员分享:jquery方法总结
老程序员分享:jquery方法总结
16 0
|
2月前
|
JavaScript 前端开发 API
jquery的一些方法
jquery的一些方法
18 1
|
2月前
|
JavaScript 索引