Saturday, December 24, 2011

function () versus $(document).ready in jQuery

<div id="immediately">Hello</div>

<div id="whendoneloading">World</div>

<script type="text/javascript">

   (function () {

      $('#immediately').attr('style', "display:none;");

      $(document).ready(function () {

         $('#whendoneloading').attr('style', "display:none;");

      });

   })();

</script>

 
 

In the blob of markup above this will run right away...

$('#immediately').attr('style', "display:none;");

 
 

...while this will run when the page finishes loading...

$('#whendoneloading').attr('style', "display:none;");

No comments:

Post a Comment