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



 

目录
打赏
0
0
0
0
6
分享
相关文章
|
6月前
|
jQuery 遍历 方法
jQuery 遍历 方法
47 5
jquery中html()方法的使用
jquery中html()方法的使用
74 1
jQuery - AJAX load() 方法
jQuery load() 方法是简单但强大的 AJAX 方法。
88 6
|
6月前
|
jQuery parentsUntil() 方法
jQuery parentsUntil() 方法
47 10
jQuery - noConflict() 方法
jQuery - noConflict() 方法
40 5
|
6月前
|
jQuery 效果 方法
jQuery 效果 方法
26 3
jQuery 杂项方法
jQuery 杂项方法
50 2
|
6月前
|
jQuery parents() 方法
jQuery parents() 方法
77 7
jQuery HTML / CSS 方法
jQuery HTML / CSS 方法
39 2
jQuery AJAX 方法
jQuery AJAX 方法
58 1