Question: I'm trying to write an unobtrusive script and I don't want to add any html that's not needed unless javascript is enabled.

Using MooTools 1.2.4, is it possible to wrap a an array of elements with say for example: tags?

Desired effect:

Before:

```
<p>Something</p>
<p>Something1</p>
<p>Something2</p>
<p>Something3</p>

```

Wishful thinking javascript code:

```
$$('p').wrapWith(new Element('div', {id: 'master'}));

```

After:

```
<div id="master">
  <p>Something</p>
  <p>Something1</p>
  <p>Something2</p>
  <p>Something3</p>
</div>

```

Answer: 
Answered on the IRC channel. Answer added for posterity.

Iterate over the elements and use `wraps` ([Fiddle](http://jsfiddle.net/keeto/9wPp5/)):

```
var els = $$('p'),
    div = new Element('div', {id: 'master'});

els.each(function(e){ div.wraps(e) });

```

Or create an `Element` method like `wraps` that accepts `Elements` instances ([Fiddle](http://jsfiddle.net/keeto/DM8eg/)):

```
Element.implement('surround', function(els, where){
    var elements = Array.slice(els), len = elements.length;
    for (var i = 0; i < len; i++){
        this.wraps(elements[i], where);
    }
    return this;
});

new Element('div', {id: 'master'}).surround($$('p'));

```
This seems to work:

**Example:** <http://jsfiddle.net/9Pqv9/>

```
var p = $$('p');
new Element('div',{id:'master'}).inject(p[0],'before').adopt(p);

```

[`Inject`](http://mootools.net/docs/core/Element/Element#Element%3ainject) the `new Element` before the first `p`, then have it [`adopt`](http://mootools.net/docs/core/Element/Element#Element%3aadopt) the entire set of `p` elements.

---

Or this, which `wraps` the first `p`, then adopts the set:

**Example:** <http://jsfiddle.net/9Pqv9/1/>

```
var p = $$('p');
new Element('div', {id: 'master'}).wraps(p[0]).adopt(p);

```