[thelist] Javascript off CSS on hide elements in page

Tony Crockford boldfish at gmail.com
Mon Mar 28 02:53:57 CST 2005


Hi all,

I have a site (sorry, protected by NDA ) that has some javascript
submits and "jump" menus  I want to provide functionality for users
surfing with javascript off, and have provided <noscript> wrapped
alternatives.

what I wanted to do was turn off (display:none) the elements that
needed javascript when they are replaced by their noscript
equivalents.

well I managed that by doing this:

<!-- hide noscript.css with javascript - no javascript - loads noscript.css -->
<script type="text/javascript">
<!--	 
document.write('<!' + '--'); 
//-->
</script>
<link rel="stylesheet" type="text/css" media="screen"
href="/sty/noscript.css" />
<script type="text/javascript">
<!--	 
document.write('--' + '>'); 
//-->
</script>

unfortunately the w3c validator balks at my code, which to my simple
brain would be valid..

what i'm trying to do is use javascript to wrap the link to the
stylesheet in comments (noscript tags are not allowed in the head)
which works in practice.

(noscript.css has just this: 
.noscript {
display: none;
}

and some modified element heights to allow for different size boxes
with/without javascript



can anyone suggest a way of getting the same results - i.e load a
stylesheet only when javascript is off - that would pass validation.

TIA


p.s. loading a counter stylesheet *with* javascript isn't really an
option unless someone can suggest a blanket opposite to display:none
that would work when some of the elements are inline and some are
block.



-- 
http://wiki.workalone.co.uk - stuff you need to know.
http://xebit.net


More information about the thelist mailing list