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.

google.load("jquery", "1.4.2");<br />

<br />

<br />

<br />

CHAPTER 1 ■ INTRODUCING JQUERY<br />

■ Note Loading the JavaScript right before the closing body tag () is done to keep the scripts from<br />

blocking other page elements, such as images, from loading. Doing so also prevents JavaScript from running<br />

before the elements are fully loaded on the page, which can result in unexpected behavior or JavaScript errors.<br />

Save this file <strong>and</strong> navigate to http://localhost/testing/ in Firefox (see Figure 1-3).<br />

Figure 1-3. Our test file loaded in Firefox<br />

You’ll be using this file to get your feet wet with the basic operations of <strong>jQuery</strong>.<br />

Introducing the <strong>jQuery</strong> Function ($)<br />

At the core of <strong>jQuery</strong> is the <strong>jQuery</strong> function. This function is the heart <strong>and</strong> soul of <strong>jQuery</strong> <strong>and</strong> is used in<br />

every instance where <strong>jQuery</strong> is implemented. In most implementations of <strong>jQuery</strong>, the shortcut $() is<br />

used instead of <strong>jQuery</strong>() to keep the code concise.<br />

We won’t get too deep into the programming theory that makes this function tick, but it basically<br />

creates a <strong>jQuery</strong> object <strong>and</strong> evaluates the expression passed as its parameters. It then determines how it<br />

should respond <strong>and</strong> modifies itself accordingly.<br />

9

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

Saved successfully!

Ooh no, something went wrong!