jQuery Basics

Once you’ve loaded the jQuery library on your page, you can start working with elements. jQuery has a function called jQuery, which lets us fetch elements using CSS selectors and wrap them in jQuery objects so we can manipulate those elements.

There’s a short version of the jQuery function, $();, and that’s what we use in this book. Throughout this book, I refer to this as “the jQuery function.” Here’s how it works:

If you wanted to find the h1 tag on a page, you’d use the following:

jqueryprimer/simple_selection.html
 
$(​"h1"​);

If you wanted to find all of the <h1> tags on the page, you’d use the exact same thing. If you were looking for all elements with the class of important, you’d do this:

jqueryprimer/simple_selection.html ...

Get HTML5 and CSS3, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.