I always add this little jQuery snippet at the beginning of my JS files.
jQuery.fn.exists = function(){return jQuery(this).length>0;}
This uses the same approach that many have suggested, but it also allows you to access whether or not such an object exists:
if ( $('#toolbar').exists() ){ $('#toolbar').load(..., function(){...});
Dutchie432 Jan 25 '11 at 16:26 2011-01-25 16:26
source share