🚧tag()

// ⭐️ tag()
function tag(name, {
    textContent,
    attributes = {}
}={}){

    // create element
    let elem = document.createElement(name);

    // set text content if necessary
    if(textContent) elem.textContent = textContent;
    
    // set attributes
    for (const [key, value] of Object.entries(attributes)) {
        elem.setAttribute(key, value);
    }
    
    // return element
    return elem;
}

Last updated