Is there any good practice to avoid your jQuery code silently fail?
For example:
$(\'.this #is:my(complexSelector)\').doSomething();
It's not necessarily wrong when a selector matches nothing; it depends on your application. You could write your own validateNonEmpty plugin:
jQuery.fn.validateNonEmpty = function() {
if (this.length == 0)
throw "Empty list detected - selector: " + this.selector;
return this; // thanks @Matt
};
Then you can do:
$('something something').validateNonEmpty().doSomething();
Also, note that you want to check to see if the length is 0, not less than 0.