:last-child
is really the only way to do it without modifying the HTML - but assuming you can do that, the main option is just to give it a class="last-item"
, then do:
li.last-item { /* ... */ }
Obviously, you can automate this in the dynamic page generation language of your choice. Also, there is a lastChild
JavaScript property in the W3C DOM.
Here's an example of doing what you want in Prototype:
$$("ul").each(function(x) { $(x.lastChild).addClassName("last-item"); });
Or even more simply:
$$("ul li:last-child").each(function(x) { x.addClassName("last-item"); });
In JQuery, you just replace the double $$
with a single $
. So
$$("ul li:last-child")
Becomes:
$("ul li:last-child")
Also note that this should work without using the actual last-child
CSS selector - rather, a JavaScript implementation of it - so it should be less buggy. I may, of course, be completely wrong.