jQuery in Action
74
CHAPTER 3
Bringing pages to life with jQuery
them. Please refer back to the syntax blocks for
append()
and
appendTo()
for the
format of the syntax for these commands.
One more thing before we move on...
Remember back in the previous chapter when we showed how to create new
Remember back in the previous chapter when we showed how to create new
HTML
fragments with the jQuery
$()
wrapper function? Well, that becomes a
really useful trick when paired with the
appendTo()
,
prependTo()
,
insertBefore()
,
and
insertAfter()
commands. Consider the following:
$('<p>Hi there!</p>').insertAfter('p img');
This statement creates a friendly paragraph and inserts a copy of it after every
image element within a paragraph element.
image element within a paragraph element.
Figure 3.6 After execution, it's clear that the car has been moved and the flower has
been copied.