Thursday, 24 May 2012

Using the jQuery Equivalent of Body OnLoad

Prior to jQuery, the way to get JavaScript to fire on loading a page was to add an onload attribute to the body HTML tag:

<body onload="mycode();">

In jQuery, this can be replaced by:

<script type="text/javascript">$(mycode);</script>

The important thing is not to include the method brackets. $(mycode()); will not work.


Web Software Outsourcing said...
This comment has been removed by the author.
Dan Randolph said...

Thanks Neil,
your tip was really helpful.