I tried to do it this:
$(this + ' li:not(:nth-last-child(2)):not(:last-child)').hide()
Full code sample:
$('.comments').each(function(){
$(this + ' li:not(:nth-last-child(2)):not(:last-child)').hide()
var template = $('#expand').html();
$(this).prepend(template)
});
I need to run it as an “each”-function because I want to put in a conditional later.
Try this:
From docs
So you can use
thisas context parameter: