I'd like to also add that Unobtrusive Javascript is just cleaner and
easier to understand than the alternative.

When I try to analyze a page that has tons of Javascript mixed with
HTML, it can be very difficult see what's going on.  Contrast that
with the unobtrusive approach where you can use CSS selectors or XPath
queries to grab the elements you care about and apply behaviours to
them.    If you're good at naming your CSS classes and ids, the code
you end up with has the potential to be so much cleaner and so much
more beautiful.

I don't even think it's more work to take this approach.

It's not a hassle compared to the maintenance nightmare you might face
otherwise with entagled Javascript and HTML.

The Separation of Concerns is a good thing.  Many significant advances
in the art of programming have been through people figuring out ways
to separating concerns from each other.  MVC separates Models, Views,
and Controllers from each other -- the benefit is understandability.
Using HTML for content and CSS for presentation is another form of
separation where two aspects of display have been separated, and
again, this makes things easier to understand and way more flexible,
because now the 2 parts can vary independently.  Javascript being
separated from HTML is yet another step in this direction.

If you're not sold on the general principles behind separating
concerns, try to imagine the opposite.

Imagine... a PHP page that makes SQL queries right before it populates
a big HTML table that makes heavy use of nested tables for layout but
also has some inlined CSS via the style attribute, and to top it all
off the HTML is littered with onclick handlers and script tags at
various places in the page.

Now imagine a whole web site built this way.  (PAIN!!!!)




That's what we're trying to get away from.

That's why we (as programmers) are always coming up with new ways to
separate concerns.

It's a trend that you ignore at your own peril.



(I'm not sure what possessed me to write so much, but I gotta post
that to my blog ;-)


On 1/24/07, Klaus Hartl <[EMAIL PROTECTED]> wrote:
> Ⓙⓐⓚⓔ wrote:
> > there are a million reasons to separate js from the html!
> >
> > but UOJS is the ability for a page to still work without javascript. A
> > very admirable feature!
>
> I'd say accessibility is one - obviously the most important - aspect of
> UOJS. You could probably code accessible without separating js and html
> but since the whole UOJS movement started adherers also consider
> separation good practice.
>
> I pretty much believe that this separation is part of UOJS, but hey,
> nowhere is there an official definition so in the end it's just another
> personal opinion.
>
> And yes of course, it is admirable :-) Everybody should be doing it!
>
>
> -- Klaus
>
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
>
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to