我想在new3
中检索最后一个子元素的类名(class last div .find_class
),但我的代码为我提供了类select3
。我该如何解决?
演示: http://jsfiddle.net/gBxan/5/
<div class="find_class mediumCell">
<div class="new1 old1">
<div class="select1"></div>
</div>
<div class="new2 old2">
<div class="select2"></div>
</div>
<div class="new3 old3"><!-- I want to get this div's class name 'new3' -->
<div class="select3"></div>
</div>
</div>
var find = $('div.find_class div:last').attr('class');
alert(find);
答案 0 :(得分:7)
使用子选择器(>
):
var find = $('div.find_class > div:last').attr('class');
答案 1 :(得分:2)
$('.find_class').children(':last').attr('class');