side_menu/src/lib/createElement.js

18 lines
412 B
JavaScript
Raw Normal View History

2022-10-16 19:57:32 +02:00
module.exports = (tagName, attributes) => {
const element = document.createElement(tagName)
if (typeof attributes === 'object') {
for (let i in attributes) {
if (i === 'text') {
element.textContent = attributes[i]
} else if (i === 'html') {
element.innerHTML = attributes[i]
} else {
element.setAttribute(i, attributes[i])
}
2022-10-16 19:57:32 +02:00
}
}
return element
}