I just spent 'hours' with the following scenario: (all back to the basics)
$('#typo').bind('click' etc ...
I had a typo in the selector, but jQuery resolves
$('#funny something out there').bind(...
without any warning.
Is it possible to tell jQuery to raise an error when your selector gets nothing?
Something like this:
$('#typo', alert('Stupid, nothing here! like '+ '#typo))
edit
I spoke against me:
$('#typo', alert('Stupid, nothing here! like '+ '#typo))
is not a solutiuon. I have to know where the error is to extend the selector
You could use following snippet:
UPDATED to take care of context
DEMO
jQuery.debug = true;
$ = function (selector, context) {
if (jQuery.debug && typeof selector === "string" && !jQuery(selector, context).length)
throw new Error("No element found!");
return jQuery.apply(this, arguments);
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With