Last active
April 18, 2016 08:46
-
-
Save yulanggong/3b1622f9a2225838e467 to your computer and use it in GitHub Desktop.
micro jQuery
This file contains hidden or 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
var $ = function(s){ | |
if(!(this instanceof $)){ | |
return new $(s); | |
} | |
this.push.apply(this, document.querySelectorAll(s)); | |
} | |
$.fn = $.prototype = []; | |
$.fn.each = function(fn){ | |
this.forEach(fn); | |
return this; | |
} | |
$.fn.remove = function(){ | |
return this.each(function(el){ | |
el.parentNode.removeChild(el); | |
}) | |
} | |
$.fn.on = function(type, fn){ | |
return this.each(function(el){ | |
el.addEventListener(type, fn, false); | |
}) | |
} | |
$.fn.hide = function(){ | |
return this.each(function(el){ | |
el.style.display = 'none'; | |
}) | |
} | |
$.fn.show = function(){ | |
return this.each(function(el){ | |
el.style.display = 'block'; | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment