Question

Is it bad to use inline JavaScript event handlers, or is that fine?

On the page I plan to use it on, I'm only going to use an event handler once, so is it acceptable to use an inline event handler in this case, or shall I write the code for the event handler within <script> tags?

Was it helpful?

Solution

Its bad practice if your concern is readability in your mark-up and maintenance, especially on a larger scale it can get quite messy - also keep in mind the inline JS will never be cached like an external js file would so you do suffer a bit in regards to performance especially if you abuse it

Read this article for more insight: http://robertnyman.com/2008/11/20/why-inline-css-and-javascript-code-is-such-a-bad-thing/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top