→ Slightly Obtrusive JavaScript

31 May 2010

There are good things and bad things about "Unobtrustive JavaScript." One bad thing: it's hard to tell what JavaScript is touching an element.

Idea: Only ever use classes and ids prefix with js- when touching the DOM with JavaScript.

For example:

<a href="#prices class="js-open-tab">Prices</a>

Now we know to look for any JavaScript touching .js-open-tab, which should only be a simple search away.

And hey, now JavaScript and CSS won't share selectors. Since we're separating our content and presentation, we might as well separate our behavior all the way too.

We could also use FireQuery, though it only works with one JavaScript library in one browser, and not with $.fn.live(). Though I do love it.