Last active
August 29, 2015 14:05
-
-
Save jayllellis/1485e91470dec9ed13cb to your computer and use it in GitHub Desktop.
jQuery check if element exists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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