Dave's Brain

Browse - Programming Tips - Where should I initialize my jQuery stuff?

Date: 2009apr2
Updated: 2011jun8
Language: javaScript, php, perl
Keywords: onLoad, load, start, begin, init

Q.  Where should I initialize my jQuery stuff?

A.  Use document.ready() like this:

<script> $(document).ready(function() { // PUT INITIALIZATION HERE }); </script>
Or if you already have a function that you want run do init things do this:
<script> $(document).ready(myInitFunction()); </script>
If you are using PHP:
print <<<EOF <script> jQuery(document).ready(function() { // PUT INITIALIZATION HERE }); </script> EOF;
If you are using Perl:
print <<EOF; <script> jQuery(document).ready(function() { // PUT INITIALIZATION HERE }); </script> EOF

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.