Skip to content

Instantly share code, notes, and snippets.

@myfreeer
Last active January 26, 2020 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myfreeer/926f3c79d57386b008e96693b0f0f061 to your computer and use it in GitHub Desktop.
Save myfreeer/926f3c79d57386b008e96693b0f0f061 to your computer and use it in GitHub Desktop.
Element.prototype.find=Element.prototype.querySelector;
Element.prototype.attr=Element.prototype.getAttribute;
Element.prototype.on=Element.prototype.addEventListener;
Element.prototype.off=Element.prototype.removeEventListener;
// arrow functions binds no this nor arguments
Element.prototype.data=function(str){return this.dataset[str];};
Element.prototype.text=function(str){return str ? (this.innerText = str) && this : this.innerText;};
Element.prototype.html=function(str){return str ? (this.innerHTML = str) && this : this.innerHTML;};
Element.prototype.hide=function(){this.style.display = 'none';};
Element.prototype.show=function(){this.style.display = '';};
Element.prototype.css=function(style){
if(typeof style === 'object') style = Object.keys(style).map(i=>i+':'+style[i]+';').join();
this.style.cssText = style;
return this;};
Element.prototype.addClass=function(){return this.classList.add(...arguments);};
Element.prototype.removeClass=function(){return this.classList.remove(...arguments);};
Element.prototype.toggleClass=function(){return this.classList.toggle(...arguments);};
Element.prototype.hasClass=function(){return this.classList.contains(...arguments);};
Element.prototype.replaceClass=function(){return this.classList.replace(...arguments);};
NodeList.prototype.map = HTMLCollection.prototype.map = Array.prototype.map;
NodeList.prototype.filter = HTMLCollection.prototype.filter = Array.prototype.filter;
NodeList.prototype.reduce = HTMLCollection.prototype.reduce = Array.prototype.reduce;
NodeList.prototype.reduceRight = HTMLCollection.prototype.reduceRight = Array.prototype.reduceRight;
NodeList.prototype.every = HTMLCollection.prototype.every = Array.prototype.every;
NodeList.prototype.some = HTMLCollection.prototype.some = Array.prototype.some;
HTMLCollection.prototype.forEach = NodeList.prototype.forEach;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment