Unobtrusive JavaScriptBrett MillettOctober 6th, 2011
What is JavaScript?Powerful scripting language that your web browser executes.Built into every major web browser.Standardized (for the most part) for all web browsers.<script>alert(“hello world!”);</script>
Why JavaScript?Makes rich interaction possible with a webpage!
AJAX: asynchronous JavaScript and XML.
The Internet would be a far less interesting place without it.What’s “obtrusive” JavaScript? HTML markup allows use of JavaScript via event attributes. The “old way” and an “obtrusive” JavaScript practice.
What’s so bad about that?Web pages are easier to update when functionality and layout are uncoupled.JavaScript must be part of the document body instead of in a cacheable external file.href=“#” example when JavaScript disabled.Everybody code like it’s 1999!
What’s unobtrusive JavaScript? Separates behavior from markup.Allows for “graceful degradation.”
Unobtrusive JavaScript ExampleCompletely separate from markup.
Reusable and globally accessible. Easier to change one function then all your markup!
Degrades gracefully.jQuery (jquery.com)Popular JavaScript framework.Extremely powerful selector syntax.

Unobtrusive js