Skip to content

Instantly share code, notes, and snippets.

@jayllellis
Last active August 29, 2015 14:05
Show Gist options
  • Save jayllellis/1485e91470dec9ed13cb to your computer and use it in GitHub Desktop.
Save jayllellis/1485e91470dec9ed13cb to your computer and use it in GitHub Desktop.
jQuery check if element exists
/**
* @desc checks if current element exists
* @param none
* @return int - the number of elements present, > 0 = element exists
*/
jQuery.fn.exists = function(){ return this.length > 0; }
// Usage:
if( $('#my-div').exists() ){
// do something
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment