# elem.wrappedWith()

{% tabs %}
{% tab title="💾 程式" %}
```javascript
/**
 * wrap this Element with another Element.
 * Note: this Element must be already in the DOM.
 * 
 * @example
 *
 *   let anchor = `<a id="${anchorID}"></a>`.htmlToElement();
 *   let heading = document.querySelector("h2");
 *   heading.wrappedWith(anchor);
 */
Element.prototype.wrappedWith = function(elem){
    this.before(elem);    // insert element before self
    elem.append(this);    // move self into element ⭐ 
};
```
{% endtab %}

{% tab title="⬇️ 應用" %}
* [table-of-contents](../../../create-insert-delete-nodes/table-of-contents "mention")
{% endtab %}

{% tab title="📗 參考" %}
* [x] JavaScript: The Definitive Guide (15.3 Scripting Document)
{% endtab %}

{% tab title="👥 相關" %}
* [create-insert-delete-nodes](../../../create-insert-delete-nodes "mention")
{% endtab %}
{% endtabs %}
