首页 > 语言 > JavaScript > 正文

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

2024-05-06 16:17:37
字体:
来源:转载
供稿:网友

这篇文章主要介绍了jQuery使用empty()方法删除元素及其所有子元素的方法,涉及jQuery操作元素的技巧,具有一定参考借鉴价值,需要的朋友可以参考下

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

 

 
  1. <!DOCTYPE html> 
  2. <html> 
  3. <head> 
  4. <script src="js/jquery.min.js"> 
  5. </script> 
  6. <script> 
  7. $(document).ready(function(){ 
  8. $("button").click(function(){ 
  9. $("#div1").empty(); 
  10. }); 
  11. }); 
  12. </script> 
  13. </head> 
  14. <body> 
  15. <div id="div1" style="height:100px;width:300px;border:1px solid black;background-color:yellow;"> 
  16. This is some text in the div. 
  17. <p>This is a paragraph in the div.</p> 
  18. <p>This is another paragraph in the div.</p> 
  19. </div> 
  20. <br> 
  21. <button>Empty the div element</button> 
  22. </body> 
  23. </html> 

希望本文所述对大家的jQuery程序设计有所帮助。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选