02.06.2013 Views

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 2 ■ COMMON JQUERY ACTIONS AND METHODS<br />

Figure 2-13. The spans are relocated to be next to one another so both can be wrapped<br />

.wrapInner()<br />

In some cases, it’s desirable to wrap the content of an element but not the tag itself. A good example of<br />

this is making an entire paragraph bold: to wrap strong tags around a paragraph is not valid HTML <strong>and</strong>,<br />

therefore, isn’t a desirable solution. Fortunately, <strong>jQuery</strong> provides .wrapInner(), which wraps everything<br />

contained within an element in a new tag.<br />

To italicize all text in the paragraphs on the test page, use the following code:<br />

$("p").wrapInner("");<br />

After execution, all the text on the page is italicized <strong>and</strong> the markup is validly nested (see<br />

Figure 2-14).<br />

51

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!