Created
June 18, 2014 14:37
-
-
Save iantearle/d17276c0d7bdc6d72e2b to your computer and use it in GitHub Desktop.
jQuery exists function
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.fn.exists = function(fn) { | |
if(this.length>0) { | |
var f = arguments[0]; | |
arguments[0] = function(e) { | |
f(e); | |
} | |
fn.apply( this, arguments ); | |
return fn ? this.bind(name, fn) : this.trigger(name); | |
} else { | |
return this.length>0; | |
} | |
} | |
// To use simply write the following: | |
$(element).exists(function() { | |
$(this) // do something; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment