This is a JQuery idiom. JQuery returns a set of matching elements as an array-like object that can be chained with further JQuery actions. You rarely index into it, because then you get the element rather than a JQuery result set. Unfortunately the only way to determine if the selector didn't match anything is to test the length. Maybe it would be less confusing if I said length > 0 here, even though it would be a problem if we got more than 1 match.