Last active
August 29, 2015 14:00
-
-
Save mirai-iro/11401781 to your computer and use it in GitHub Desktop.
if ($('#hoge').length > 0) { ...と書くのがめんどうだった
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
/*! | |
* jQuery.isExist | |
* written by mirai-iro. | |
* https://gist.github.com/mirai-iro/11401781 | |
* Released under the MIT license. | |
*/ | |
(function($){ | |
$.fn.isExist = function(){ | |
return($(this).length > 0); | |
} | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if ($('#hoge').length > 0) {
// #hoge があるときの処理
}
↓
if ($('#hoge').isExist()) {
// #hoge があるときの処理
}