Last active
March 21, 2018 19:54
-
-
Save viniceosm/ad5016d26924867cf9f958522a7f1c5e to your computer and use it in GitHub Desktop.
vkek - manipular o DOM
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
function Vkek(){ | |
// this.el será o elemento buscado apartir do Vkek.$() | |
} | |
Vkek.prototype = { | |
$: function(selector) { | |
if (typeof selector == 'string') { | |
this.el = (document.querySelectorAll(selector).length > 1) ? document.querySelectorAll(selector) : document.querySelector(selector); | |
} else { | |
this.el = selector; | |
} | |
return this; | |
}, | |
addEvent: function(eventName, fn) { | |
this.el.addEventListener(eventName, fn); | |
return this; | |
}, | |
click: function(fn){ | |
this.el.addEventListener('click', fn); | |
return this; | |
}, | |
load: function(fn){ | |
window.addEventListener('load', fn); | |
return this; | |
}, | |
html: function(html){ | |
if (html == undefined) { | |
return this.el.innerHTML; | |
} | |
this.el.innerHTML = html; | |
return this; | |
}, | |
each: function(fn){ | |
for (i in this.el) { | |
fn(this.el[i], i); | |
} | |
} | |
} | |
function vkek(selector) { | |
_vkek = new Vkek(); | |
if (selector != undefined){ | |
_vkek.$(selector).el; | |
} | |
return _vkek; | |
} |
Author
viniceosm
commented
Mar 21, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment