# 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](/web/browser/dom/create-insert-delete-nodes/table-of-contents.md)
  {% endtab %}

{% tab title="📗 參考" %}

* [x] JavaScript: The Definitive Guide (15.3 Scripting Document)
  {% endtab %}

{% tab title="👥 相關" %}

* [create/insert/delete nodes](/web/browser/dom/create-insert-delete-nodes.md)
  {% endtab %}
  {% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lochiwei.gitbook.io/web/browser/dom/type/element/+ext/elem.wrappedwith.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
