Friday, September 30, 2011

wrap(Element)

wrap(Element elem) returns jQuery

Wrap all matched elements with a structure of other elements. This wrapping process is most useful for injecting additional stucture into a document, without ruining the original semantic qualities of a document.

This works by going through the first element provided and finding the deepest ancestor element within its structure - it is that element that will en-wrap everything else.

This does not work with elements that contain text. Any necessary text must be added after the wrapping is done.

Example:


$("p").wrap( document.getElementById('content') );

HTML:
<p>Test Paragraph.</p><div id="content"></div>

Result:
<div id="content"><p>Test Paragraph.</p></div>

No comments:

Post a Comment