Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.