Another idea is that if the seletor doesn't select any elements,
return null (as does getElementById() in that case):
...
but that may not be backward compatible.  Of what use is an empty
jQuery object?

An empty jQuery object doesn't break chainability:

$('#foo').hide();

Will hide the element with ID foo if it exists. Otherwise, it does
nothing. If null were returned, that would generate a javascript
error, so you would have to always check for the existence of the
element if you wanted to be sure you didn't generate an error.

This is one of the sweetest features of jQuery.

--Erik

Reply via email to