Skip to content

Instantly share code, notes, and snippets.

@georgebrock
Created December 13, 2009 13:48
Show Gist options
  • Save georgebrock/255420 to your computer and use it in GitHub Desktop.
Save georgebrock/255420 to your computer and use it in GitHub Desktop.
/*
Get a warning when jQuery finds no matches for a selector
Handy for debugging, although I wouldn't want it in production
*/
jQuery.oldFind = jQuery.find;
jQuery.find = function(sel) {
var result = jQuery.oldFind.apply(jQuery, arguments);
if(typeof(sel) == "string" && result.length == 0) {
console.warn("Nothing matches selector: ", sel);
}
return result;
}
jQuery(function($) {
$("div"); // Finds stuff
$("foo"); // Finds nothing
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment