Skip to content

Instantly share code, notes, and snippets.

@mirai-iro
Last active August 29, 2015 14:00
Show Gist options
  • Save mirai-iro/11401781 to your computer and use it in GitHub Desktop.
Save mirai-iro/11401781 to your computer and use it in GitHub Desktop.
if ($('#hoge').length > 0) { ...と書くのがめんどうだった
/*!
* 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);
@mirai-iro
Copy link
Author

if ($('#hoge').length > 0) {
// #hoge があるときの処理
}

if ($('#hoge').isExist()) {
// #hoge があるときの処理
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment