使用jquery但是2个实例选择Last子级

时间:2013-02-25 17:02:41

标签: jquery jquery-selectors parent-child

我有两个包含DL DT DD的div,我想选择div的每个最后一个DT。但是它只从最后一个DIV中选择了DT。

HTML:

<div class=pack>
<dl>
<dt>Photos</dt>
<dd>asd</dd>

<dt>Videos</dt>
<dd>asd</dd>

<dt>Infographics</dt>
<dd>ads</dd>
</dl>
</div>

<div class=pack>
<dl>
<dt>Photos</dt>
<dd>asd</dd>

<dt>Videos</dt>
<dd>asd</dd>

<dt>Infographics</dt>
<dd>ads</dd>
</dl>
</div>

jQuery的:

$('.pack dl').find('dt').last().css({"background" : "none" });

问题是,jquery只选择第二个DIV class = pack

中的最后一个DT

2 个答案:

答案 0 :(得分:1)

$('.pack ul').each(function(){
    $(this).find('li').last().css({"background" : "none" });
});

答案 1 :(得分:0)

感谢@Brad M,每种方法都有效。

$('.pack dl').each(function(){
        $(this).find('dt').last().css({"background" : "none" });
    });