Last active
August 29, 2015 14:06
-
-
Save jcgertig/daa56c711de5897029a3 to your computer and use it in GitHub Desktop.
Basic jQuery functions
This file contains 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
Element.prototype.attr = function(name, value) { | |
if (typeof value === 'undefined') { | |
return this.getAttribute(name); | |
} | |
return this.setAttribute(name, value); | |
}; | |
Element.prototype.val = function(value) { | |
if (typeof value === 'undefined') { | |
return this.value; | |
} | |
return (this.value = value); | |
}; | |
Element.prototype.css = function(name, value) { | |
if (typeof value === 'undefined') { | |
if (typeof name === 'object') { | |
var css = name; | |
Object.keys(css).forEach(function(name){ | |
this.style[name] = css[name]; | |
}.bind(this)); | |
return this.style; | |
} | |
return this.style[name]; | |
} | |
return (this.style[name] = value); | |
}; | |
Element.prototype.click = function(handler) { | |
return this.addEventListener('click', handler); | |
}; | |
Element.prototype.on = function(event, handler) { | |
return this.addEventListener(event, handler); | |
}; | |
var $ = function(selector) { | |
return document.querySelector(selector); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment