jQuery Plugin: Element Existence

February 24, 2009 in jQuery Plugins

Just a Quick little snippet really.. Over at JqueryForDesigners.com @rem mentioned about checking if an element exists or not, I’ve been doing this for some time using the following snippet: jQuery.fn.exists = function() { return (this.length > 0); }; to use it you can now do this: if ($('#elem').exists()) { /* do something */ } [...]