gpt4 book ai didi

jquery - 如何删除
内的所有内容

转载 作者:行者123 更新时间:2023-12-01 00:35:35 25 4
gpt4 key购买 nike

我有以下内容:

<div id="test">

...
...

</div>

我想删除 div 中的所有元素,所以我尝试了:

$('#test > div').remove();

但这似乎不起作用。我在这里做的事情正确吗?

最佳答案

尝试使用正确的语法

Remove : Remove the set of matched elements from the DOM.

 $('div#test').remove();

尝试使用 empty

empty : Remove all child nodes of the set of matched elements from the DOM.

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

参见html() 另外,有时它很有帮助

html: When .html() is used to set an element's content, any content that was in that element is completely replaced by the new content.

注意:要删除元素而不删除数据和事件,请使用 .detach()相反。

关于jquery - 如何删除 <div> 内的所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6000073/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com