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.

12<br />

CHAPTER 1 ■ INTRODUCING JQUERY<br />

Figure 1-4. The Firebug console after executing a comm<strong>and</strong><br />

Selecting Tags <strong>by</strong> Class Name<br />

Just as quickly as you can select <strong>by</strong> tag type, you can select elements <strong>by</strong> their assigned class or classes.<br />

The syntax for this is the use the class name preceded <strong>by</strong> a period (.):<br />

.class<br />

Select all the elements with the class foo <strong>by</strong> executing the following snippet in the console:<br />

$(".foo");<br />

After execution, the following will show up in the console:<br />

>>> $(".foo");<br />

[ p.foo, span.foo ]<br />

Both a paragraph tag <strong>and</strong> a span are returned, since they both have the class foo.<br />

Selecting Elements <strong>by</strong> ID<br />

To select an element <strong>by</strong> its id attribute, the CSS syntax of the id preceded <strong>by</strong> a hash sign (#) is used.<br />

#id<br />

Match all elements with an ID of bar with the following:<br />

$("#bar");

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

Saved successfully!

Ooh no, something went wrong!