Skip to content

Instantly share code, notes, and snippets.

@iantearle
Created June 18, 2014 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iantearle/d17276c0d7bdc6d72e2b to your computer and use it in GitHub Desktop.
Save iantearle/d17276c0d7bdc6d72e2b to your computer and use it in GitHub Desktop.
jQuery exists function
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