(^112) ❘ CHAPTER 4 MANIPULATING CONTENT AND ATTRIBUTES
padding: 15px;
}
p.quoteAttribution {
font-style: italic;
}
The following JavaScript demonstrates how content can be inserted before and after the
element,
via the respective before() and after() methods:
$(document).ready(
function()
{
$('p').before(
'
Quote
');
$('p').after(
"
\n" +
" - Groucho Marx\n" +
"
);
}
);
Figure 4-12 shows what happens when you load the preceding document in a browser.
FIGURE 4-12
The content passed to the before() method is inserted before the <p> element, and the content
passed to the after() method is inserted after the <p> element.
Inserting Beside Content via a Selection
The before() and after() methods are used to insert content beside elements. The insertBefore()
and insertAfter() methods do the same function, but instead of passing content directly to these