Skip to content

Commit

Permalink
Merge pull request #495 from NoroffFEU/#493-Create-html-function-for-…
Browse files Browse the repository at this point in the history
…the-listings

creates a createHtml function
  • Loading branch information
Olekrr authored Jan 8, 2024
2 parents 1657561 + fba6967 commit 461b618
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/js/templates/CreateHtml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export const createElement = (tagName, classes, children, text, link, src, alt) => {

const element = document.createElement(tagName);
if(Array.isArray(classes)) {
element.classList.add(...classes);
}
if(Array.isArray(children) && children.length) {
element.append(...children);
}
if(text) {
element.textContent = text;
}
if(link) {
element.href = link;
}

if(tagName === 'img') {
element.src = src;
element.alt = alt;
}

return element;
};

0 comments on commit 461b618

Please sign in to comment.