Just several TIPS on Adding jQuery to a Page

Here are a few things to keep in mind:

  • The link to the jQuery file must precede any programming that relies on jQuery. In other words, don’t put any other script tags before the <script> tag that loads jQuery.

  • Put your JavaScript programming after any CSS stylesheets (both linked, external stylesheets and internal stylesheets). Because jQuery programming often references styles from a stylesheet, you should put your JavaScript programming after the web browser has loaded any styles. A good rule of thumb is to put your JavaScript programming (all your <script> tags) after any other content inside the <head> tag, but before the closing </head> tag.

  • Add a JavaScript comment—for example, //end ready—after the }); that marks the end of the ready() function. For example:
    $(document).ready(function() {
            // your programming goes here
    }); // end ready

Putting a comment at the end of the function makes it easy to identify the end of the program.

As you’ll see later, jQuery often requires lots of little collections of this brace, parenthesis, and semicolon trio. By adding a comment after them, it’ll be much easier to identify which group of punctuation belongs to which part of your program.


Popular Posts