Crawford Design

Logo

Javascript

JavaScript should be kept separate from HTML in a .js file just as CSS is kept separate in a .css file. Separate .js files reduce clutter, don't lock out users who have JavaScript disabled in their browsers, and won't interfere with other JavaScript code that might be applied to the same page. Keeping JavaScript separate is called unobtrusive scripting.

By using unobtrusive scripting, JavaScript can be applied to an HTML page through classes and IDs just like CSS. There is no need to put JavaScript on the page.

The JavaScript library, JQuery, contains JavaScript that will ensure that the DOM loads first before any scripts are executed. The JQuery Web site contains examples of unobtrusive scripting.

The publication, Simply JavaScript by Kevin Yank and Cameron Adams, also explains in detail how to do unobtrusive scripting. With the purchase of the book, you will be able to download examples of unobtrusive JavaScript as well as scripts that will ensure your HTML page loads before JavaScript runs.

Please refer to the W3C for: Using functions of the Document Object Model (DOM) to add content to a page (Scripting)

References

Top