jquery如何删除包装div?

Pat*_*cow 1 jquery jpeg

我有这个:

<div class="test"><div id="123"><img class="image" src="1.jpg"></div></div>
<div class="test"><div id="123"><img class="image" src="2.jpg"></div></div>
Run Code Online (Sandbox Code Playgroud)

我想做的是if(img.attr("src") == ("1.jpg"){ remove the entire div that hosts that image}变成这样:

div class="test"><div id="123"><img class="image" src="2.jpg"></div></div>
Run Code Online (Sandbox Code Playgroud)

div有同一类.谢谢

Joh*_*hnP 6

编辑更新的答案以反映有问题的变化

只需一行就可以了:)

$('img[src="1.jpg"]').parents('div.test').remove();
Run Code Online (Sandbox Code Playgroud)

http://api.jquery.com/parents/

要么

$('img[src="1.jpg"]').closest('div.test').remove();
Run Code Online (Sandbox Code Playgroud)

http://api.jquery.com/closest/