Check body load (or other item)

I want to show my div (wrapper) when the body is loaded. This is my code:

$("div.wrapper").hide();
$('body').load(function() {
    $('.wrapper').show();
});

But my code is not working. What is my mistake?

+5
source share
4 answers

Description

.ready () Specify the function to execute when the DOM is fully loaded.

So, make your div invisible with cssand make it visible with jQuery.

Example

Html

<div class="wrapper" style="display:none">
   <!-- your content -->
</div>

JQuery

$(document).ready(function() {
   $('.wrapper').show();
});

Full example

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
    <head>
        <title></title>

        <script type="text/javascript" src="PathToYourJqueryJsFile" />
        <script type="text/javascript">
            $(document).ready(function () {
                $('.wrapper').show();
            });
        </script>
    </head>
    <body>
        <div class="wrapper" style="display:none">
        <!-- your content -->
        </div>  
    </body>
</html>

Additional Information

+7
source

First install .wrapper {display:none}css in your file. Then this code should show it after the page loads:

$(document).ready(function() {
    $('.wrapper').show();
});
+3
source
  • jquery, jquery? , , $ Enter.

  • jQuery

    $(document).ready(function() {// });

edit : this is the same as $ (function () {}); style, but I prefer a more detailed style

0
source

use jquery and just do

<script>
    $(function(){ //jquery short-hand for DOM ready!!!
        $('.wrapper').show(function(){ 
             console.log('I AM SHOWING!!');
        });
    });
</script>
0
source

All Articles