选择具有相同类的2个div中的最后一个img

web*_*ker 4 html css jquery jquery-selectors

我有两个具有相同类的div .productList,并希望<img>用jQuery 操纵两个div中的第二个.

我有以下几点;

$('div.productList').each(function(){
    $('img:last-child').css('margin-left','10px');
});
Run Code Online (Sandbox Code Playgroud)

标记(部分)

<div class="productList">
<img src="images/parts/" width="120" height="120" alt="" title="" />
<img class="last" src="images/parts/" width="120" height="120" alt="" title="" />
Run Code Online (Sandbox Code Playgroud)

我假设使用.each()循环遍历每个div并找到最后一个img,但这对我不起作用.

请问有人请指出我正确的方向吗?

谢谢.

Eth*_*ang 5

只需使用css来做到这一点:

div.productList img:last-child {
    margin-left: 10px;
}
Run Code Online (Sandbox Code Playgroud)