Sams Teach Yourself HTML, CSS & JavaScript Web Publishing in One Hour a Day

(singke) #1
ptg16476052

Workshop 525

18


$("#country").load($(this).attr('href'));
$("#country").fadeIn();
});
});





To read about other AJAX-related methods offered by jQuery, take a look at the jQuery
API documentation. Most of the other jQuery methods are more suitable to application
development , but they essentially work in a similar fashion to the load() method that
you saw here.


Summary


In this lesson, I explored some of the powerful features common to most JavaScript
libraries using jQuery. You learned which JavaScript libraries are available and why you
might want to use them. You also learned how to include jQuery in a web page and take
advantage of its functionality through the document.ready() event. I explained how
event binding works with jQuery and how to dynamically modify the styles on a page as
well as the content of a page itself. Finally, I explained what AJAX is and how jQuery
and other JavaScript libraries enable you to make requests to external data sources from
within a web page.


Workshop


As always, we wrap up the lesson with a few questions, quizzes, and exercises. Here are
some questions and exercises that should refresh what you’ve learned about jQuery.


Q&A


Q Won’t adding jQuery cause my pages to load more slowly?

A Yes, adding any JavaScript library will add to your overall page size. However, the
browser will cache the external JavaScript file, so users should only have to down-
load it once, when they get to the first page of your site. When they go to subse-
quent pages, the JavaScript library will already be in the cache.


Another option to help speed up your pages that use jQuery is to use a content
delivery network or CDN. These are repositories of many different JavaScript
libraries that you can link to in your web pages to take advantage of the global
cache. Chances are your customers have already visited a page that uses a CDN
for jQuery so it’s already in their cache and you can take advantage of that. The
CDN I use for jQuery is at https://code.jquery.com/. Simply link to the version of

Free download pdf