Created
May 9, 2013 17:03
-
-
Save phillbaker/5548865 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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: | |
// <button id="start">Start</button> | |
// | |
// 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)); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment