Created
June 18, 2017 15:05
-
-
Save kadavre/8f9c70a039678da3508c54c4fb50d294 to your computer and use it in GitHub Desktop.
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
// Old way | |
console.log($('#elem').length == 1 ? "exists!" : "doesn't exist!"); | |
// The trick: | |
jQuery.fn.exists = function(){ return this.length > 0; } | |
console.log($('#elem').exists() ? "exists!" : "doesn't exist!"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment