Next Post: Filter the Django ModelAdmin set
oct
2008
Grinds my gears; Inline JavaScript
You know what really grinds my gears?
JavaScript embedded inside HTML; Why do we even need this functionality anymore? Are there any good arguments in its favour? Besides laziness.
Using event handlers in an external file (or even in a script block) allows you to keep your code and HTML separate and clean! This is really useful and makes for maintainable, easier to read and easier to document code. It also improves re-usability as its easier to move around and just re-map the event handlers without hunting through HTML to find them.
Event handlers are more powerful. Managing multiple handlers and re-using handlers on different elements and/or different events is far easier than doing the same in HTML. Particularly if you use something like jQuery and selectors.
...and that people is what grinds my gears!
Yeah, ok so for some simple examples and demo's it is easier to add in-line code. It makes sense, so its just one file (ie. Google maps api code examples have css and js inline). However, with any serious website it doesn't really make sense.
Next Post: Filter the Django ModelAdmin set
Short url - Related tags: grinds-my-gears, javascript