1

I need to show this div after 3 seconds on my page.

    <div id="cratepop">
    <br>
    <center><img src="/shoppingcart.png"></center>
    <br>
    </div>

Tried using this but it's not working. Any help?

        <script type="text/javascript">
    require(['jquery'],function($ ){


  $(document).ready(function(){
        setTimeout(function(){
        $('#cratepop').show();
        }, 3000);     


        });


    });
</script>

3 Answers 3

0
<div id="cratepop" style="display:none;">
    <br>
        <center><img src="/shoppingcart.png"></center>
    <br>
</div>

jQuery Code:

jQuery(document).ready(function(){
        setTimeout(function(){
            jQuery('#cratepop').show();
        }, 5000);     
});

The only one thing you have to do is HIDE your DIV using CSS.

jSfiddle - https://jsfiddle.net/wqq8Lcka/13/

Note: I dont recommend you to use inline CSS. this is just for an example.

8
  • Do I have to include the REQUIRE portion?
    – Joe
    Nov 2, 2017 at 19:35
  • No.. 1st try removing it.. Nov 2, 2017 at 19:36
  • jQuery is not defined error
    – Joe
    Nov 2, 2017 at 19:45
  • Current code <script type="text/javascript"> jQuery(document).ready(function(){ setTimeout(function(){ jQuery('#cratepop').show(); }, 5000); }); </script>
    – Joe
    Nov 2, 2017 at 19:45
  • thats because jQuery is not added in your site. Now try with REQUIRED portion.. Which was your original Nov 2, 2017 at 19:46
0

I can't add comments yet so.. You are using this code:

jQuery(document).ready(function(){
    setTimeout(function(){
        jQuery('#cratepop').show();
    }, 5000);     
});

But in require you alias jquery as $ so simply replace jQuery with $ in above code.

0

Add style="display:none;" in your code and everything will work fine.

   <div id="cratepop" style="display:none;">
    <br>
    <center><img src="/shoppingcart.png"></center>
    <br>
    </div>

Also try to show alert after 3 seconds..for testing purpose only :)

 <script type="text/javascript">
    require(['jquery'],function($ ){

  $(document).ready(function(){
        setTimeout(function(){
        alert('Joe is good');//for testing purpose only
        $('#cratepop').show();
        }, 3000);     
        });
    });
</script>

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.