I working with jQuery and I need to get anytime and anywere exception (with any operation), if I attach some event or try to perform some action with elements (got from selector) that don't exist. Is there some internal "strict" mode in jQuery for this issue?
No, there isn't.
However, you could make a simple plugin for it:
$.fn.checkEmpty = function() {
if (!this.length)
throw new Error("No elements matched by " + this.selector);
return this;
};
$('...').checkEmpty().bind(...);
Alternatively:
function $s() { return $.apply(this, arguments).checkEmpty(); }
$s('...').bind(...);
Check this post for ways to handle an "exists"
Exists in jquery
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