Reputation: 3
jQuery $("div span[z*='w']:last-child").css({color: "red"});
and the 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?
Live example http://jsbin.com/izubaj/edit#javascript,html,live
Upvotes: 0
Views: 319
Reputation: 25081
I may be misunderstanding the question, but I think you want the span
that has "Sam 2" as well as "David".
<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'});
Upvotes: 0
Reputation: 41757
Your selector actually chooses the span
elements and then applies the last child pseudo selector to that collection, try the following:
$("div").find('span[z*="w"]:last').css({color: "red"});
See here for update.
Upvotes: 1