Java Reference
In-Depth Information
a framework, be sure to download and use the compressed version, because its file sizes are
smaller and download faster.
Note The production version of jQuery 2.1.1 is provided in the code
download from Wrox.
You can obtain jQuery in one of two ways. First, simply download whichever version you prefer by
right‐clicking (or control‐clicking on a Mac) the link, and save it in a location you can easily get to.
Alternatively, you can use jQuery's Content Delivery Network (CDN) to add jQuery to your web
pages. This prevents you from having to download your own copy of jQuery, and it can also slightly
increase the performance of your web pages.
Regardless of how you obtain jQuery, you add it to your pages just like any other external
JavaScript file with the <script/> element:
<script src="jquery-2.1.1.min.js"></script>
<script src="//code.jquery.com/jquery-2.1.1.min.js"></script>
The only difference is the value of the src attribute. The first <script/> element in this example
uses a local copy of jQuery 2.1.1, whereas the second uses jQuery's CDN. The examples in this
chapter use a local copy of jQuery.
jQuerY's api
jQuery is JavaScript, but it changes the way that you interact with the browser and document.
Whether you're creating HTML elements and appending them to the page or making Ajax calls to
the server, jQuery lets you do it in an easy fashion.
At the heart of jQuery is the jQuery() function, but in most cases, you won't write your code with
jQuery() . Instead, you'll use an alias: the dollar function, $() . This can seem very weird at first, but
it will become completely natural the more you use it.
You'll use the $() function for just about everything, including:
Finding and selecting elements
Creating, appending, and removing elements
Wrapping normal DOM objects with jQuery objects
selecting elements
jQuery revolutionized the way developers find elements in the DOM: with CSS selectors. In fact,
the querySelector() and querySelectorAll() methods discussed in Chapter 9 exist because of
jQuery. To retrieve elements with jQuery, you use $() and pass it your CSS selector, like this:
var elements = $("a");
 
Search WWH ::




Custom Search