Separation of Behavior From Markup
Traditionally, JavaScript was often placed inline together with an HTML document's markup. For example, the following is a typical implementation of JavaScript form validation when written inline:
Adherents to "Unobtrusive Javascript" argue that the purpose of markup is to describe a document's structure, not its programmatic behavior and that combining the two negatively impacts a site's maintainability for similar reasons that combining content and presentation does. They also argue that inline event handlers are harder to use and maintain, when one needs to set handlers for several events on a single element, when one wants to set the same event handler on several elements, or when one is using event delegation. Nor can they be used with custom events.
The unobtrusive solution is to register the necessary event handlers programmatically, rather than inline. Rather than adding the onchange attribute explicitly as above, the relevant element(s) are simply identified, for example by class, id or some other means in the markup:
A script that runs when the page is first loaded into the browser can then look for the relevant element(s) and set them up accordingly:
window.onload = function { document.getElementById('date').onchange = validateDate; };Read more about this topic: Unobtrusive Java Script
Famous quotes containing the words separation of, separation and/or behavior:
“There is nothing that I shudder at more than the idea of a separation of the Union. Should such an event ever happen, which I fervently pray God to avert, from that date I view our liberty gone.”
—Andrew Jackson (17671845)
“... the separation of church and state means separationabsolute and eternalor it means nothing.”
—Agnes E. Meyer (18871970)
“There are ... two minimum conditions necessary and sufficient for the existence of a legal system. On the one hand those rules of behavior which are valid according to the systems ultimate criteria of validity must be generally obeyed, and on the other hand, its rules of recognition specifying the criteria of legal validity and its rules of change and adjudication must be effectively accepted as common public standards of official behavior by its officials.”
—H.L.A. (Herbert Lionel Adolphus)