// jQuery Plugin ifExists // v0.0.1 // @phillbaker // // To be used if you want to call a (non-core jquery) function on the result of a jquery selector. // // Example: // // html: // // // js: // $("#start").ifExists( // function(elem){ // elem.animate({marginTop:20},function(){alert('ok')}).addClass('aaa'); // } // ); // // http://jsfiddle.net/andres_314/vbNM3/2/ // http://stackoverflow.com/a/11768171 $.fn.ifExists = function(fn) { if (this.length) { $(fn(this)); } };