HTML and CSS Reference
In-Depth Information
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 particu-
larly 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 JavaScript functions
themselves and be sure to not include the HTML <script> tags. No additional code is required
beyond the functions. For example, take the getCurrentTime() function used in the previous
lesson. When located in the <head> of the HTML source code, the function was enclosed in a
<script> tag and HTML comments, like this:
<script type=”text/javascript”>
<!--
function getCurrentTime() {
var theAM_PM;
var theDate = new Date();
Search WWH ::




Custom Search