Friday, May 25, 2012

Genuine class

I love web development. It's so...mature...integrated...well thought-out...tooled-up...yeah.

Just found the following stupid bug, and I don't intend to be a smart-Alec about it. It's trivial. So, we do these jquery things .live('click', function ...) or whatever. And we use 'class' for this. After some  refactoring, let's call it that, a clickable link changes behavior. 

Turns out that the rewrite put two 'class' attributes in the same element tag. The first class attribute contained some styling. The second class attribute contained the 'class' that controls the click action. The second class attribute is ignored.

The syntax-coloring html editor of the Eclipse I use does not flag this as a problem.

Conclusions: don't use 'class', use attributes. They are not as clumsy, except that they kind of have to be prefixed 'data-', so that tools don't color it in warning yellow, and the web can use new attributes in the brighter future. They also can have values. Also, find or invent better editing tools. Turn on html syntax warnings in browser, if it has them.

No comments:

Post a Comment