Skip to content

Instantly share code, notes, and snippets.

@yulanggong
Last active April 18, 2016 08:46
Show Gist options
  • Save yulanggong/3b1622f9a2225838e467 to your computer and use it in GitHub Desktop.
Save yulanggong/3b1622f9a2225838e467 to your computer and use it in GitHub Desktop.
micro jQuery
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