If we don't like it for the presentation layer, then why do we tolerate it for the behavior layer?

Posted by greim on Stack Overflow See other posts from Stack Overflow or by greim
Published on 2010-04-13T06:37:21Z Indexed on 2010/04/13 6:43 UTC
Read the original article Hit count: 277

Filed under:
|
|
|

Suppose CSS as we know it had never been invented, and the closest we could get was to do this:

<script>
// this is the page's stylesheet
$(document).ready(function(){
    $('.error').css({'color':'red'});
    $('a[href]').css({'textDecoration':'none'});
    ...
});
</script>

If this was how we were forced to write code, would we put up with it? Or would every developer on Earth scream at browser vendors until they standardized upon CSS, or at least some kind of declarative style language?

Maybe CSS isn't perfect, but hopefully it's obvious how it's better than the find things, do stuff method shown above. So my question is this. We've seen and tasted of the glory of declarative binding with CSS, so why, when it comes to the behavioral/interactive layer, does the entire JavaScript community seem complacent about continuing to use the kludgy procedural method described above? Why for example is this considered by many to be the best possible way to do things:

<script>
$(document).ready(function(){
    $('.widget').append("<a class='button' href='#'>...</div>");
    $('a[href]').click(function(){...});
    ...
});
</script>

Why isn't there a massive push to get XBL2.0 or .htc files or some kind of declarative behavior syntax implemented in a standard way across browsers? Is this recognized as a need by other web development professionals? Is there anything on the horizon for HTML5?

(Caveats, disclaimers, etc: I realize that it's not a perfect world and that we're playing the hand we've been dealt. My point isn't to criticize the current way of doing things so much as to criticize the complacency that exists about the current way of doing things. Secondly, event delegation, especially at the root level, is a step closer to having a declarative behavior layer. It solves a subset of the problem, but it can't create UI elements, so the overall problem remains.)

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about html