[英]jquery :last-child did not work properly
jQuery $("div span[z*='w']:last-child").css({color: "red"});
jQuery $("div span[z*='w']:last-child").css({color: "red"});
and the html 和HTML
<div>
<span z="ww">Sam</span> <!-- Didn't works -->
<span>Sam 2</span>
</div>
<div>
<span z="ww">Glen,</span>
<span z="ww">David</span> <!-- Works -->
</div>
How to select the span from the first div? 如何从第一个div中选择范围?
Live example http://jsbin.com/izubaj/edit#javascript,html,live 实例http://jsbin.com/izubaj/edit#javascript,html,live
尝试这个:
$("span[z*='w']:last", 'div').css({color: "red"});
I may be misunderstanding the question, but I think you want the span
that has "Sam 2" as well as "David". 我可能误解了这个问题,但我认为你想要的是“Sam 2”以及“David”的span
。
<div>
<span z="ww">Sam</span> <!-- Didn't works -->
<span>Sam 2</span>
</div>
If that's the case, try: 如果是这种情况,请尝试:
$('div span[z*="w"]').siblings(':last-child').css({color: 'red'});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.