I know. I was checking for null objects first and then I thought...hmmm I wonder if jQuery will take care of that... and there is no error thrown on on clicking the first or last checkbox.
I think it's because a jQuery makes collections instead of gathering objects, so testing for
will always return true even if there is no element with an id "foo" because that's just a collection, it's not a real DOM object - you have to do
to turn it into a DOM element, or
to test if the collection is not empty (ie, the element does in fact exist)
that's the way I understand it works, anyway. Could be completely wrong. The posted code works, though - feel free to give it a run