admin管理员组文章数量:1391929
I have a function that appends dynamic a
and img
tags to a specific div ID :
$('<a class="fap-single-track" href=""><img src=".jpg').appendTo("#status_01");
But I want the user to be able to update this link (elsewhere on the page).
How do I remove the appended data from #status_01 when I don't know exactly what the data is going to be (the url and image links are being gathered from a remote API).
The problem I'm having is that when the user selects a new URL to populate the appendTo data, the old one is also there, so I end up with multiple <a>
& <img>
sets.
I've tried a bunch of different ways but nothing seems to work.
If I :
$('#status_01').remove(); // before adding new data
The status_01 DIV is no longer available in the dom for the next function.
$('#status_01').detach();
Doesn't work either.
I've also tried and mixture of prepend and some other stuff but none of it seems to get rid of the appendTo data.
Is it possible?
Or maybe there is something other than appendTo that I can use instead to attach the data in the first place?
I have a function that appends dynamic a
and img
tags to a specific div ID :
$('<a class="fap-single-track" href="http://web."><img src="http://web./image.jpg').appendTo("#status_01");
But I want the user to be able to update this link (elsewhere on the page).
How do I remove the appended data from #status_01 when I don't know exactly what the data is going to be (the url and image links are being gathered from a remote API).
The problem I'm having is that when the user selects a new URL to populate the appendTo data, the old one is also there, so I end up with multiple <a>
& <img>
sets.
I've tried a bunch of different ways but nothing seems to work.
If I :
$('#status_01').remove(); // before adding new data
The status_01 DIV is no longer available in the dom for the next function.
$('#status_01').detach();
Doesn't work either.
I've also tried and mixture of prepend and some other stuff but none of it seems to get rid of the appendTo data.
Is it possible?
Or maybe there is something other than appendTo that I can use instead to attach the data in the first place?
Share Improve this question edited Feb 11, 2016 at 10:20 Mr Lister 46.6k15 gold badges113 silver badges155 bronze badges asked Feb 3, 2016 at 16:08 GrantGrant 1,3372 gold badges17 silver badges40 bronze badges 1-
yes have tried
$(this).closest('#status_01').find('a.fap-single-track').remove();
but that's not doing it either – Grant Commented Feb 3, 2016 at 16:11
2 Answers
Reset to default 3This maybe ?
$('#status_01').html("");
Or, if you want to only remove the last :
$('#status_01').children().last().remove();
In addition to @Remy's correct answer, you can also use .empty():
$('#status_01').empty();
本文标签: javascriptRemoving an AppendTo element jQueryStack Overflow
版权声明:本文标题:javascript - Removing an AppendTo element jQuery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744739658a2622533.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论