Skip to content

Instantly share code, notes, and snippets.

@jCrip
Created September 3, 2013 22:49
Show Gist options
  • Save jCrip/6430660 to your computer and use it in GitHub Desktop.
Save jCrip/6430660 to your computer and use it in GitHub Desktop.
Check if Element Exists
// Tiny jQuery Plugin
// by Chris Goodchild
$.fn.exists = function(callback) {
var args = [].slice.call(arguments, 1);
if (this.length) {
callback.call(this, args);
}
return this;
};
// Usage
$('div.test').exists(function() {
this.append('<p>I exist!</p>');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment