Questioning unobtrusive JavaScript

Over at Web Graphics, David Lindquist presents a controversial query: “Inline JavaScript: What’s the Problem?”

So then, what is the problem with using inline JavaScript in moderation? After all, it is simply a name=”value” attribute pair like all the others. Why is class=”someclass” acceptable and onclick=”dosomething(this)” is not?

The post prompted lots of good comments, many of them giving detailed reasons for avoiding inline event handlers.

If you’ve read, glanced at, or even just picked up my book, you’ll know where I stand on this issue. Unobtrusive, good; inline, bad.

That said, it’s not the worst thing in the world to have inline event handlers. It’s more a matter of best practices.

If you styled your pages using inline styles, there wouldn’t be anything technically wrong with that. It’s just that, from a maintenance and readability standpoint, it can make your own life more difficult.

It’s much the same with adding behaviour inline. You can do it, but you’d be much better off keeping all your behaviour externalised.

Posted by Jeremy on Sunday, November 13th, 2005 at 7:06pm

Comments

I think the biggest argument inliners have is how to tie in JavaScript built in with a much larger architecture. I too (agreeing with Jeremy) believe that there is always another workaround that one has yet to think of.

It should always be as easy as passing in a className of a sort and use that as a hook to add behavior. on[event] is a mirrored effect of the style attribute, but for JavaScript.

# Posted by Dustin Diaz on Tuesday, November 15th, 2005 at 12:28am

Sorry. Comments are closed.

November 2005
SunMonTueWedThuFriSat
  12345
6789101112
13141516171819
20212223242526
27282930   

Recommended Reading

XML Subscribe

Grab the RSS feed for this blog.

JavaScript API

Grab the RSS feed of comments for this entry.