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.

26<br />

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

• Access to all attributes of an element, including CSS <strong>and</strong> styling properties, <strong>and</strong><br />

the ability to modify them<br />

• Animation <strong>and</strong> other effects<br />

• Simple AJAX controls<br />

■ Note The preceding list is only a partial list of <strong>jQuery</strong>’s features <strong>and</strong> capabilities. As you continue on through the<br />

projects in this book, other helpful features will be explored. As always, for a complete reference, visit the<br />

documentation at http://api.jquery.com.<br />

Traversing DOM Elements<br />

Traversal in <strong>jQuery</strong> is the act of moving from one DOM element to another; traversal is essentially<br />

another form of filtering performed after the initial selection has been made. This is useful because it<br />

allows developers to complete an action <strong>and</strong> then move to another part of the DOM without needing to<br />

perform another search <strong>by</strong> selector.<br />

It also aids developers in affecting the elements immediately surrounding an element that is being<br />

manipulated or otherwise utilized <strong>by</strong> a script. This can range from adding a class to parent elements to<br />

indicate activity to disabling all inactive form elements to any number of other useful tasks.<br />

■ Note You will be using the same HTML test file from Chapter 1 for the examples in this chapter as well. If you're<br />

using XAMPP to test locally, point your browser to http://localhost/testing/ to load this file. Make sure the<br />

Firebug console is open <strong>and</strong> active (see Chapter 1 for a refresher on using the Firebug console).<br />

.eq()<br />

If a set of elements needs to be narrowed down to just one element identified <strong>by</strong> its index, then you’re<br />

able to use the .eq() method. This method accepts one argument: an index for the desired element. For<br />

.eq(), indices start at 0.<br />

$("p").eq(1);<br />

When executed in the Firebug console, the following returns:<br />

>>> $("p").eq(1);<br />

[ p.foo ]<br />

Additionally, a negative number can be supplied to .eq() to count backward from the end of the<br />

selection set (e.g., passing -2 will return the second-to-last element from the set).

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

Saved successfully!

Ooh no, something went wrong!