如何使用JQuery删除元素的内容? [英] How to remove an element's content with JQuery?

查看:75
本文介绍了如何使用JQuery删除元素的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个div和其中的一些内容.

Say I have a div and some content inside it.

<div>
      Content
</div>

使用JQuery,如何在不删除div的情况下清空div,而只删除其中的内容?

With JQuery, how do I empty the div without removing the div, only the content inside?

推荐答案

您可以使用函数删除元素的所有子节点(所有内容):

You can use the empty function to remove all the child nodes (all its content) of an element:

$('#elementId').empty();

empty函数还将删除所有事件处理程序和jQuery内部缓存的数据.

The empty function will also remove all the event handlers and the jQuery internally cached data.

这篇关于如何使用JQuery删除元素的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆