Unobtrusive JavaScript

Unobtrusive JavaScript is a way of thinking JavaScript. It’s a set of guidelines to make the web better that are constantly being rethought. It shouldn’t even be called ‘Unobtrusive JavaScript’ but rather something like ‘JavaScript best practices’, which is what it really is.

Unobtrusive JavaScript means

  • A separation of structure and behaviour
  • Do not make any assumptions (meaning don’t expect things to work or exist, test for it)
  • Features should be added in lieu of progressive enhancement
  • Your site should work without JavaScript (note: as of the 10th of January 2014, newer browsers are removing the ability to disable JavaScript in the browser, so this dying)
  • Leave CSS things to CSS (e.g. use JS to toggle classes, leave the styling or animations to CSS)

There’s a lot more to it, of course, and I’d recommend you proceeding with these references: