ifExists
Execute if the element exist
by andres_314
HTML
<button id="start">Start</button>
JavaScript
$.fn.ifExists = function(fn) {
if (this.length) {
$(fn(this));
}
};
$.fn.logger = function(msg) {
console.log(msg);
return this;
};
$("#start").ifExists(
function($this){
$this.addClass('aaa').animate({marginTop:20},function(){alert('ok')}).logger('log something');
}
);