Separating behavior
The modern understanding of a web page is that it consists of three distinct parts:
- Content (HTML)
- Presentation (CSS)
- Behavior (JavaScript)
These should be kept separate, ideally each in its own file (or files). What it means for JavaScript is that there should be no inline such as onclick, onmouseover, etc. Ideally there should be little to no inline scripts.
The idea is that content (the text on the page) is independent of:
- how it looks like, so the page should be usable even with CSS disabled, or not supported by the browser, and
- how it behaves, meaning the page should be usable even with JavaScript disabled. The content should be accessible independent of any mouseovers, animations, and so on.
Tags: behavior, separation of concerns