# newElement()

{% tabs %}
{% tab title="💾 程式" %}
:floppy\_disk: replit: [elem.showNote()](https://replit.com/@pegasusroe/elemshowNote#script.js)

```javascript
// ⭐️ newElement()
/*
 * create and configure a new Element
 * 
 * @param {string}   tagName  - like 'div', 'span' ...
 * @param {function} config   - function to configure the newly created element
 * @return {Element}
 */
function newElement(tagName, config) {
    let elem = document.createElement(tagName);
    if (config) { config(elem) }
    return elem;
}
```
{% endtab %}

{% tab title="📗 參考" %}
* [x] JS.info ⟩ [Show a note near the element](https://tr.javascript.info/coordinates#show-a-note-near-the-element)
{% endtab %}

{% tab title="📘 手冊" %}
* [document](../../document "mention") ⟩ [.createElement()](https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement)
{% endtab %}
{% endtabs %}
