If I were to remove my CSS stylesheet and set all the properties via a JavaScript file, would that be possible? That is, would there be anything I couldn't access via the JS DOM API?
I'm not sure if you can set different media types like "print" from in javascript.
[edit]
Actually, I take that back. You might be able to use cssText to do it.
The only ones I can think of are possibly IE CSS expressions (such as ones commonly used to fix PNGs in IE6).
However I don't think this is generally a good idea, as you want to keep your content (HTML), layout (CSS) and logic (javascript) seperate for maintainability reasons. Not to mention if people visit your site with javascript disabled.
Everything in CSS can be accessed through JS, but bear in mind that users with JS disabled won't get any style at all!
- CSS is for styling
- JavaScript is for changing functionality
Don't merge them unless strictly necessary.
A lots of interesting information about the DOM to CSS interface can be read from the W3C Document Object Model CSS2 Specification. For CSS3, they are still working on it.
So it is possible to manipulate any css property through CSS DOM stylesheets but it depends on what the browser supports.
I'm pretty sure that having the browser execute all that JS just to set a style would be much slower than applying a stylesheet, and possibly be more prone to cross browser problems.
Great question: "would there be anything I couldn't access via the JS DOM API?"
I think the answer is yes. See below:
IE8 now wants this for the opacity property: -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"
so does anyone know how to change this property dynamically with Javascript DOM access (DHTML)?
Point taken?