Saturday, January 22, 2011

Three ways for initialization tasks in Javascript: $(handler), Onload() and pageLoad()

1. pageLoad(), it is called for every partial postback. We should put JQuery event handlers in this function.

2. window.onload = function () {alert("onload");}

Onload() event will be called only after the DOM and associated resources like images got loaded


3. JQuery $(document).ready(handler)
jQuery's document.ready() event will be called once the DOM is loaded, it wont wait for the resources like images to get loaded

All three of the following syntaxes are equivalent:
  • $(document).ready(handler)
  • $().ready(handler) (this is not recommended)
  • $(handler)

Reference:
http://api.jquery.com/ready/




If useful, Consider making a donation to show your support.