Skip to content

Instantly share code, notes, and snippets.

@avi-flombaum
Created November 26, 2012 14:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save avi-flombaum/4148429 to your computer and use it in GitHub Desktop.
Save avi-flombaum/4148429 to your computer and use it in GitHub Desktop.
jQuery.exists
// Calls function on $ if it is an existing piece of dom.
// $('foo.bar').exists(function(){$("#target").show();}) -> foo.bar will appear where foo.bar is present
// $('foo.baz').exists(function(){$("#target").show();}) -> foo.baz will not appear where foo.baz is not present
jQuery.fn.exists = function(func){if (this[0]) {if (func){func.apply(this, arguments);} else {return true;}} else {if (func){return this;} else {return false;}};};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment