Friday, September 30, 2011

wrap(String)

wrap(String html) 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 (which is generated, on the fly, from the provided HTML) and finds 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("<div class='wrap'></div>");

HTML:
<p>Test Paragraph.</p>

Result:
<div class='wrap'><p>Test Paragraph.</p></div>

No comments:

Post a Comment