Skip to content

Instantly share code, notes, and snippets.

@jeremyredhead
Created October 3, 2017 18:13
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 jeremyredhead/59f32387dad967b15f10fd7eeaf86417 to your computer and use it in GitHub Desktop.
Save jeremyredhead/59f32387dad967b15f10fd7eeaf86417 to your computer and use it in GitHub Desktop.
Lazy? the JS "Library"
/* Lazy?, the JS "Library" is (c) Jeremy Wilhelm, licensed MIT */
window.doc = document
window.head = document.head
window.body = document.body
window.$ = document.querySelector.bind(document)
window.$$ = document.querySelectorAll.bind(document)
Element.prototype.byId = Element.prototype.getElementById
Element.prototype.byClass = Element.prototype.getElementsByClassName
Element.prototype.byTag = Element.prototype.getElementsByTagName
Element.prototype.getAttr = Element.prototype.getAttribute
Element.prototype.setAttr = Element.prototype.setAttribute
Element.prototype.delAttr = Element.prototype.removeAttribute
Element.prototype.getData = function(attr) { return this.getAttribute('data-' + attr) }
Element.prototype.setData = function(attr, value) { this.setAttribute('data-' + attr, value) }
Element.prototype.delData = function(attr) { this.removeAttribute('data-' + attr) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment