/ Gists / jQuery exists fn
On gists

jQuery exists fn

jQuery Helpers-Filters-Plugins
@see: https://css-tricks.com/snippets/jquery/check-if-element-exists/

jquery-exists-fn.js Raw #

// 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>');
});