Summary
In this article, you’ve seen how you can use the JavaScript progressive enhancement techniques to enrich and enliven your HTML markup. However, before you rush to use this exciting technique, carefully consider whether the same effects could be achieved without JavaScript; the introduction of an additional JavaScript library will make your pages look slightly different to visitors that have disabled the JavaScript as well as slightly increase the server load and page download times.
Last but not least, dynamic changes to HTML formatting are often a source of confusing hard-to-debug problems.
If you have convinced yourself that the JavaScript is the only answer to your formatting/design challenge, use it wisely:
- Observe the rules of JavaScript progressive enhancement and avoid inserting any JavaScript code in your HTML markup.
- Always use a CSS class or HTML ID attribute to indicate which elements should be acted upon. This will prevent your code from modifying the elements that should not be changed.
- Define all changes to the page formatting as CSS rules and make the rules as specific as possible (for example, use TABLE.printout TR.EvenRow instead of just .EvenRow). Do not modify the style properties of individual HTML elements unless it’s absolutely necessary, as this will make your code more complex and harder to change.