Skip to content

Instantly share code, notes, and snippets.

@bjdixon
Created April 27, 2015 13:17
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 bjdixon/af44af12d95ee9ea0aaf to your computer and use it in GitHub Desktop.
Save bjdixon/af44af12d95ee9ea0aaf to your computer and use it in GitHub Desktop.
Extend jquery with function to check if an element exists
//extend jquery with function to check if element exists
$.fn.exists = function(){
return this.length > 0 ? this : false;
}
//usage
$('.matchme').exists(); //returns reference to element if exists otherwise false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment