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
Your selector actually chooses the
spanelements and then applies the last child pseudo selector to that collection, try the following:See here for update.