I have a dynamic list and need to select the before last item.
&l
Probably a neater way but how about:
var lastLiId = $(".album li:last").prev("li").attr("id");
You can use .eq() with a negative value (-1 is last) to get n from the end, like this:
-1
n
$(".album li").eq(-2).attr("id"); // gets "li-9"
You can test it here.