On Oct 20, 2007, at 8:41 AM, figo2476 wrote:
e.g.
<ul>
<li>a</li>
<li>b</li> <-
<li>c</li> <-
</ul>
I did:
<script type="text/javascript">
$(document).ready(function() {
$("#update li:last").addClass("last_li");
$(jQuery.sibling("#update
li:last").prev).addClass("sec_last_li");
});
</script>
The last element works, but not the 2nd last....
Hi there,
Your "second to last" line could be rewritten like this:
$("#update li:last").prev().addClass("sec_last_li");
You could also write it like this:
$('#update li').slice(-2, -1);
It probably makes sense, though, to chain the two selections:
$("#update li:last").addClass("last_li").prev().addClass
("sec_last_li");
And finally, to make it a bit more readable, you can break that into
two lines:
$("#update li:last").addClass("last_li")
.prev().addClass("sec_last_li");
Hope that helps.
--Karl
_________________
Karl Swedberg
www.englishrules.com
www.learningjquery.com