Chapter 22. Advanced JavaScript

In the previous lesson, you got your first look at JavaScript and how it integrates with HTML on a basic level. JavaScript is a very robust language made even more valuable in recent years by enhancements to the JavaScript engines incorporated in modern browsers. Now JavaScript functions execute faster than ever — which has lead to an explosion of development particularly in the area of JavaScript code libraries, also known as frameworks.

There's an amazing wealth of freely available JavaScript functionality already developed in these frameworks that you can apply to your websites — all you need to know is how. In this lesson you learn how to work with one of the most popular JavaScript frameworks, jQuery, and integrate its code into your own starting with the key step of linking to external JavaScript files.

LINKING EXTERNAL FILES

Just like external CSS files are the best approach to styling an entire website, consolidating your JavaScript functions in one or more external documents is the preeminent method for adding enhanced functionality. To externalize your JavaScript, you'll need two elements: a page of JavaScript functions and a <script> tag linking to that page from your source code.

Creating a JavaScript file is very straightforward and can be accomplished with any text editor. In essence, you simply move any JavaScript functions from your main page, whether located in the <head> or <body> sections, to a blank text file. You must move only the ...

Get HTML5 24-Hour Trainer 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.