> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/web/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/web/browser/dom/custom/tag.md).

# tag()

{% tabs %}
{% tab title="💾 程式" %}

```javascript
// ⭐️ 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;
}
```

{% endtab %}

{% tab title="⬇️ 應用" %}

* [Element](/web/browser/dom/type/element.md) ⟩ [.appendTag()](/web/browser/dom/type/node/+ext/.appendtag.md)
* [helper functions](/web/appendix/custom/helper-functions.md)
  {% endtab %}
  {% endtabs %}
