Web Development with jQuery®

(Elliott) #1

Manipulating HTML and Text Content (^) ❘ 121
function()
{
$('p').wrapInner('');
}
);
In Figure 4-16, you see that the contents of all three

elements are each wrapped with
tags, making the contents of each

element styled with yellow backgrounds, appearing to high-
light the content of all three paragraphs.


FIGURE 4-16


As demonstrated by what you see in Figure 4-16, the wrapInner() method takes the contents of each
individual element present in a selection and places that content in a wrapper.

Unwrapping Elements


Unwrapping elements using the unwrap() method means removing the parent element from one or
more elements and placing those element(s) in its place. The following example, Example 4-12, dem-
onstrates jQuery’s unwrap() method in the context of the preceding wrapping examples that have
been presented thus far.

<!DOCTYPE HTML>
<html lang='en'>
<head>
<meta http-equiv='X-UA-Compatible' content='IE=Edge' />
<meta charset='utf-8' />
<title>Mitch Hedberg Quotes</title>
<script src='../jQuery.js'></script>
<script src='../jQueryUI.js'></script>
<script src='Example 4-12.js'></script>
<link href='Example 4-12.css' rel='stylesheet' />
</head>

http://www.it-ebooks.info

Free download pdf