[thelist] Re-defining CSS via Javascript

Christian Heilmann codepo8 at gmail.com
Sat Feb 17 11:45:43 CST 2007


> Hello,
>   I'm wondering whether/how its possible to re-write CSS styles via Javascript? I read the SwitchyMcLayout article on ALA, and it got me thinking - could I change the z-index of a div based on the window size of the browser?

Without an example page that is a bit tricky to do.

Generally you can change the z-index of an element with the style
property. Say if your element has the ID "main" it'll be:

var obj = document.getElementById('main');
obj.style.zIndex = 100;

You can read the window size of the browser with window.innerWidth.

These examples should get you on the way:
http://beginningjavascript.com/Chapter5/index.html

Easiest would be a demo URL though.

-- 
Chris Heilmann
Book: http://www.beginningjavascript.com
Blog: http://www.wait-till-i.com
Writing: http://icant.co.uk/



More information about the thelist mailing list