admin管理员组文章数量:1401469
I have the following html:
<div id="container"><img src="some/path/image.jpg" /></div>
I want to remove that image by using a function. However, i'm not very experienced with javascript and I can't get it done because the image element has no ID or class.
$("button").click(function () {
$("container").remove("container > img");
});
However obviously that doesn't work. Please help!
I have the following html:
<div id="container"><img src="some/path/image.jpg" /></div>
I want to remove that image by using a function. However, i'm not very experienced with javascript and I can't get it done because the image element has no ID or class.
$("button").click(function () {
$("container").remove("container > img");
});
However obviously that doesn't work. Please help!
Share Improve this question asked Feb 2, 2012 at 1:32 Daan TwiceDaan Twice 3371 gold badge3 silver badges15 bronze badges 1- docs.jquery./Tutorials – user1106925 Commented Feb 2, 2012 at 1:43
4 Answers
Reset to default 7$("#container").find("img").remove();
that should do the trick.
Your code is perfect. However instead of just using the container, You should use # before it.
$("#container > img")
$("container") should be $("#container").
I would suggest $("#container").empty()
try this, could works...
$("button").click(function () {
//get the images
var myImages = $('#container').find('img');
for (var i =0; i< myImages.length; i++){
//remove each image
$('#container').removeChild(myImages[i]);
}
});
本文标签: javascriptremove image without ID from div with IDStack Overflow
版权声明:本文标题:javascript - remove image without ID from div with ID - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744199832a2594913.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论