Last active
May 21, 2019 15:57
-
-
Save itsalb3rt/2eb160656ee5c247b3e51bff0711f40f to your computer and use it in GitHub Desktop.
Crear elementos del doom utilizando javascript
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 createElement(tagName, id = null, __class = null, src = null,customAtribute = null) { | |
let element = document.createElement(tagName); | |
element.setAttribute('id', (id == null) ? '' : id); | |
if (Array.isArray(__class)) { | |
__class.forEach(item => { | |
element.classList.add(item); | |
}); | |
} else { | |
element.classList.add((__class == null) ? 'none' : __class); | |
} | |
if (tagName == 'img') { | |
element.src = src; | |
} | |
if(Array.isArray(customAtribute)){ | |
customAtribute.forEach(atributes=>{ | |
for(let key in atributes){ | |
element.setAttribute(key,atributes[key]) | |
} | |
}) | |
} | |
return element; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment