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>
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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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