jQuery | empty()及其示例

empty()方法是jQuery中的一个内置方法,用于删除选定元素的所有子节点及其内容。

null

语法:

$(selector).empty()

参数: 此方法不接受任何参数。

返回值: 此方法返回所选元素,其中包含empty()方法所做的指定更改。

下面的示例演示了jQuery中的empty()方法:

例子:

<!DOCTYPE html>
< html >
< head >
< title >The empty Method</ title >
< script src =
</ script >
<!-- jQuery code to show the working of this method -->
< script >
$(document).ready(function() {
$("button").click(function() {
$("body").empty();
});
});
</ script >
< style >
div {
width: 200px;
height: 100px;
margin: 10px;
padding: 20px;
background-color: lightgreen;
font-weight: bold;
font-size: 20px;
}
button {
margin: 10px;
}
</ style >
</ head >
< body >
< div >
Hello !
< p >Welcome to < span >GeeksforGeeks</ span >.</ p >
</ div >
<!-- click on this button to see the change -->
< button >Click here..!</ button >
</ body >
</ html >


输出: 单击按钮之前: 图片[1]-jQuery | empty()及其示例-yiteyi-C++库 单击按钮后,将不会显示任何内容: 图片[2]-jQuery | empty()及其示例-yiteyi-C++库

© 版权声明
THE END
喜欢就支持一下吧,技术咨询可以联系QQ407933975
点赞14 分享