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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

Figure 2-9. Span text appears bold <strong>and</strong> italicized after wrapping it with strong <strong>and</strong> em tags<br />

To use a callback function to generate the desired HTML tag to wrap an element with, you must<br />

return a tag from the callback. For instance, to wrap all spans with the class foo in strong tags <strong>and</strong> all<br />

other spans in em tags, execute the following code:<br />

$("span").wrap(function(){<br />

return $(this).is(".foo") ? "" : "";<br />

});<br />

After executing this snippet, the browser shows one span in italics, <strong>and</strong> the other (the one with class<br />

foo) in bold (see Figure 2-10).<br />

47

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

Saved successfully!

Ooh no, something went wrong!