sam*_*ami 77 javascript jquery
我.append
用来添加div
$(this).append('<ul><li>test</li></ul>');
Run Code Online (Sandbox Code Playgroud)
<ul>
如果它存在于儿童中,我如何搜索并删除它$(this)
?
Jos*_*h K 84
你可以用remove()
.有关jQuery remove()的更多信息.
$(this).children("ul").remove();
Run Code Online (Sandbox Code Playgroud)
请注意,这将删除所有子 ul
元素.
elb*_*and 20
相反的.append()
是.prepend()
.
.prepend()方法将指定的内容作为jQuery集合中每个元素的第一个子元素插入(要将其作为最后一个子元素插入,请使用.append()).
我意识到这不符合OP的具体情况.但它确实回答了问题标题.:)这是谷歌"jquery对立追加"的第一次打击.
Fré*_*idi 18
使用remove()方法:
$(this).children("ul").remove();
Run Code Online (Sandbox Code Playgroud)
RoT*_*oRa 13
您还应该考虑的是保持对已创建元素的引用,然后您可以轻松地将其删除:
var newUL = $('<ul><li>test</li></ul>');
$(this).append(newUL);
// Later ...
newUL.remove();
Run Code Online (Sandbox Code Playgroud)
我遇到了同样的问题,而且我遇到过这个问题 - 这实际上对我有用:
// $("#the_div").contents().remove();
// or short:
$("#the_div").empty();
$("#the_div").append("HTML goes in here...");
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
103786 次 |
最近记录: |