2

I currently have a div in my HTML that is initially hidden (using display:none).

<div class="fulladdress">
   <p>Only display the contents of this div when an element is clicked!</p>
</div>

I then use the following Javascript so when the .autocompleteitem item is clicked, it displays:

$(document).ready(function() {

    $(document).on('click','.autocompleteitem:not(.autocompleteitemwithcontainer)',function(){
        $("div.fulladdress").show();
    });
});

However, if Javascript is disabled, the full address will never display. How do I resolve this?

4
  • 1
    You can make things to be hidden/shown via CSS properties instead. Commented Apr 17, 2017 at 9:15
  • Check for this post Link for stack overflow post Commented Apr 17, 2017 at 9:17
  • Someone briefly posted a link about using jQuery's hide and I've now adjusted my code to use this instead. Makes perfect sense :) Commented Apr 17, 2017 at 9:20
  • 1
    You can directly use $(".fulladdress").show(); instead of using DIV with it. Commented Apr 17, 2017 at 9:24

5 Answers 5

3

Maybe try working with the tag <noscript>. It runs the code inside it if the javascript is disabled.

Sign up to request clarification or add additional context in comments.

2 Comments

I had considered this, but will it display if I already have the .fulladdress hidden with CSS?
Not sure but i think you can show the div with the document. and then the option to show, or you can just create the div inside the <noscript> , but i dont think you want that
2

Use following HTML code. Now user can see the div when javaScript disabled by user or device not support javaScript. You can customize your div by select .fulladdress class on CSS.

 <noscript>
     <div class="fulladdress">
        <p>Only display the contents of this div when an element is clicked!
        </p>
     </div>
</noscript>

Comments

0

You can try something like this.

If javascript enabled - Hide div on document ready and then show on click event

If javascript disabled your document ready function wont execute and it wont hide the div

$(document).ready(function() {
    $("div.fulladdress").hide();
    $("#button").on('click',function(){
        $("div.fulladdress").show();
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="fulladdress">
   <p>Only display the contents of this div when an element is clicked!</p>
</div>
<div class="button">
   <button id="button">display</button>
</div>

7 Comments

I understand that the div is hidden via CSS, and jQuery is only used to show it. So the actual question is how to show a div hidden by CSS (display: none) without using JavaScript. I also understand, that it's not quite acceptable to show the hidden div if JavaScript is disabled. It's still better be hidden and then shown (but not with JavaScript).
In such cases this is the trick. Make css property to show div and if javascript is enabled then in document ready function hide it or change css property to display :none. hence if javascript is disabled it will display the div
True, and it would be ok, if the default (as far as I understand the question) allows for the div to be visible if JavaScript is disabled. However, the author still wants it to be hidden, even if JavaScript is disabled, and toggled if the user clicks the div. There are ways to do it without JavaScript I believe.
Yup i agree that i have suggested answer which is not a exact answer but how would you detect click event if javascript is disabled? Either he has to display the error page if javascript is disabled if he is using javascript functionality.
There are pseudo classes in CSS which might suit the needs. For example, if the user hovers over the div it would display the .fulladdress, and it can be achieved with :hover pseudo class in CSS. The click can be registered in CSS by using checkbox pseudo class properties (which is somewhat of a hack, but does work), etc.
|
0

Try this

<noscript>
    <style type="text/css">
        .pagecontainer {display:none;}
    </style>
    <div class="noscriptmsg">
    You don't have javascript enabled.
    </div>
</noscript>

Comments

0

If you absolutely have to have your div hidden at first even with JavaScript disabled and only then revealed, then there are some ways to deal with it.

Hope this helps!

Comments

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.