given this html
<div class="my_div">a</div>
<div class="my_div">b</div>
<div class="my_div">c</div>
<div>other</div>
I want select all .my_div element, but not last element from this class, this works not correct
$(".my_div:not(:last-child)").css({
color: "#090"
});
how can select all element from some class, except last element?
:last-childis exactly that, the last child, not the last child of a given tag.jQuery offers the
:lastselector, which does what you want, but has the cost of being something jQuery does rather than something the browser does. Thus:Live Example | Source