Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function createEl(type, attr, ...content) {
- const element = document.createElement(type);
- for (const item in attr) {
- if (item == 'class') {
- element.classList.add(attr[item]);
- } else if (item == 'disable') {
- element.disabled = attr[item];
- } else {
- element[item] = attr[item];
- }
- }
- for (let item of content) {
- if (typeof item == 'string' || typeof item == 'number') {
- item = document.createTextNode(item);
- }
- element.appendChild(item);
- }
- return element;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement