Wrapping an array of elements.

Posted by fivetwentysix on Stack Overflow See other posts from Stack Overflow or by fivetwentysix
Published on 2010-12-28T05:46:38Z Indexed on 2010/12/28 5:54 UTC
Read the original article Hit count: 136

Filed under:
|

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>

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about mootools