Skip to content

Instantly share code, notes, and snippets.

@hejrobin
Last active October 1, 2015 13:19
Show Gist options
  • Save hejrobin/9dfd2962954e25c13dca to your computer and use it in GitHub Desktop.
Save hejrobin/9dfd2962954e25c13dca to your computer and use it in GitHub Desktop.
console.log($('some.selector').exists());
$('some.other.selector').exists(function(){
/* I've got the maaagic in meeee */
})
do (window, jQuery) ->
unless jQuery.fn.exists
unless callback? or typeof callback isnt 'function'
callback = => @length > 0
callback.apply this
return
(function(window, jQuery) {
var callback;
if (!jQuery.fn.exists) {
if (!((typeof callback !== "undefined" && callback !== null) || typeof callback !== 'function')) {
callback = (function(_this) {
return function() {
return _this.length > 0;
};
})(this);
}
callback.apply(this);
}
})(window, jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment