May 27, 2010

How to show hidden div when javascript is disabled?

Question by Jitendra Vyas

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}

Answer by deceze

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>

Answer by Starx

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

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!