1

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}
1

4 Answers 4

14

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>
Sign up to request clarification or add additional context in comments.

4 Comments

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 The problem being that <noscript> can't be used in the <head> (AFAIK).
You are correct. But yeah, either way, your solution is much better than using javascript to actually hide all the divs on page load.
working now I just added `document.write('<style type="text/css" media="screen">#map { display: none; }</style>'); ' at top of my external javascript
3

You could use a noscript tag:

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

Comments

2

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

Comments

2

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

1 Comment

If the javascript is disabled in the client, your external js will not work anyway

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.