tags:

views:

246

answers:

4

I'm hiding a div using display:none and this div only shows when we click on + icon. but if JavaScript is disabled then I want to show that div by default on. How to do this?

I can't post whole code for now.

jQuery(document).ready(function() {
  jQuery('a#toggle').click(function() {
       jQuery('#map').slideToggle(400);
       return false;

});

CSS

#map {display:none}
+2  A: 

While rendering on server don't set display:none to that div. During page load on client set display:none using JavaScript.

prostynick
+12  A: 

Only hide it if Javascript is enabled:

<head>
    <script type="text/javascript" charset="utf-8">
        document.write('<style type="text/css" media="screen">#map { display: none; }</style>');
    </script>
</head>
deceze
I feel this is a better solution to the above 2, because the others will cause your page to flicker once it's loaded and all the divs are hidden with jQuery, if JS is enabled. I would suggest just including a different stylesheet in `<noscript></noscript>` tags that just overrides the default `display:none;` with `display:block;`
Strelok
@strelok The problem being that `<noscript>` can't be used in the `<head>` (AFAIK).
deceze
+1.. I agree. This is a better solution than mine.
Senthil
@deceze. You are correct. But yeah, either way, your solution is much better than using javascript to actually hide all the divs on page load.
Strelok
working now I just added `document.write('<style type="text/css" media="screen">#map { display: none; }</style>');' at top of my external javascript
metal-gear-solid
+1  A: 

You could use a noscript tag:

<noscript>
<style type="text/css" media="screen">#map { display: block !important; }</style>
</noscript>
ammoQ
+1  A: 

I think

<noscript>Your browser does not support JavaScript!</noscript>

This would be a better idea that other

Put the division you want to show if the javascript is not enable inside <noscript> tags

Starx
how to do in external js?
metal-gear-solid
If the javascript is disabled in the client, your external js will not work anyway
Starx
and exactly that i want
metal-gear-solid