« Back to home

The whys of Unobtrusive JavaScript

The HTML standards provide attributes on many elements, enabling you to set them up to call JavaScript when an event occurs. For example, a text field might use the onchange attribute to call some JavaScript to trim whitespace from the beginning and end of the value: <input type="text" id="field1" name="username" onchange="trim(‘field1’);"> However, this method of working has gradually become unpopular. Instead, most now seem to recommend setting up all the events on a page using a JavaScript routine; a practice called unobtrusive JavaScript.…

Read more »