jQuery if not first item

I have a collection of list items. I want to do something to all but the first one. The below code does not work… sadly…

if(!$('#numericGradesList li:first'))

try something like

$('#numericGradesList li:not(:first)').addClass('someclass');


$('#numericGradesList li:not(:first)').each(function(){

Obviously you’d need to change the “addClass” part with whatever you want to do

A jQuery object in a boolean context will always evaluate to true, because it’s an object. If you want to determine if it contains anything then you should check its length property. E.g.

if ( $('something').length > 0 ) {...}

// or:
if ( $('something').length ) {...}

// or:
if ( $('something')[0] ) {...}