Previous Message
Next Message

css vs. javascript?

Sent by Paul Novitski on 10 April 2005 07:07


At 07:07 PM 4/9/2005, Adam Pasztory wrote:
>But you have to admit that there is quite a bit of overlap.  That is, you 
>can do many of the same things with client-side javascript or css.
>(So I wouldn't call it an orthogonal relationship.)  For example, you can 
>implement a link hover effect with either one.
>
>Is the general opinion of people on this list that, given the choice 
>between a CSS implementation and a JS implementation, CSS is 
>preferable?  Are there any exceptions?


Adam,

Ha, you're asking the members of a CSS listserve if they prefer CSS or 
JavaScript?  I think the response you get will be fairly predictable.

The question of whether to choose one or the other never really comes up, 
in my experience.  That very narrow band of overlap between CSS & 
Javascript is almost entirely that of :hover/mouseover.  Other of 
JavaScript's behavioral features such as onclick, onchange, onload, timers, 
logic looping, and the modification of the DOM are outside of CSS's 
reach.  If JavaScript is used to change the styling of page elements, such 
as hiding & showing blocks via the display property or the toggling of a 
block's background image, that's most often JavaScript enabling CSS, not 
replacing CSS.  JavaScript can't replace CSS in a web-standards XHTML page 
because by itself JavaScript has no way to style the page.  CSS can't 
replace JavaScript (outside :hover for mouseover) because it is not an 
active script that can interact with the user or other environmental 
variables.  You may be thinking of Microsoft's expression() technology 
which occurs in stylesheets, but that's not CSS, it's JavaScript.

In my view, in that very narrow band of overlap between the two 
technologies, CSS is definitely preferable.  It's my impression that CSS is 
supported more widely across browsers (albeit with variances) and can't as 
easily be -- isn't as commonly -- turned off by the user.

Just look at the aspect of graceful degrading.  If CSS isn't supported by a 
browser, the page falls back to vanilla HTML rendering which is generally 
going to present the user with a page that's perfectly functional, just 
different in appearance.  If JavaScript is turned off or not supported, 
it's usually some functionality that's missing and the page will tend to be 
broken.  (Exceptions are easy to imagine; I'm talking general cases.)

I use client-side scripting very sparingly these days, and then only for 
non-critical functionality such as input validation or dynamic features 
that are in every case backed up by redundant server-side equivalents, so 
that the page will be equally functional whether JavaScript is active or 
not.  The main difference is one of responsiveness: JavaScript can take 
actions in microseconds that take several seconds in a round trip to the 
server & back.

In contrast, I use CSS in every page I write, whether scripting is present 
or not.

Paul 


______________________________________________________________________
css-discuss [EMAIL-REMOVED]]
http://www.css-discuss.org/mailman/listinfo/css-d
List wiki/FAQ -- http://css-discuss.incutio.com/
Supported by evolt.org -- http://www.evolt.org/help_support_evolt/
Previous Message
Next Message

Message thread:

Possibly related: