Drupal provides methods for implementing JavaScript. Using these methods will help to keep your code clean and to ensure compatibility with the way other modules implement JavaScript.
A couple of simple principles guide Drupal's JavaScript approach:
· All pages should be perfectly functional without scripts. JavaScript provides alternatives or supplements - not replacements - for standard elements.
·
No JavaScript is hard-coded into pages. Rather, actions are attached dynamically to page elements--and only if the needed JavaScript support is present.