Is there a 'not found' exception for jquery selector?

后端 未结 4 1466
孤街浪徒
孤街浪徒 2021-01-18 08:56

I just spent \'hours\' with the following scenario: (all back to the basics)

 $(\'#typo\').bind(\'click\' etc ...

I had a typo in the selec

4条回答
  •  长情又很酷
    2021-01-18 09:40

    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);
    };
    

提交回复
热议问题