I was working with $(window).load()
...and found one issue.
开发者_开发百科Actually as per this function first window should load and then any implementation under this function should start working.
This works fine for IE but not for FF.
in FF its working like $(document).ready()
can somebody suggest any alternate approach, or the reason why FF behave like this.
Your second method is the preferred method, working for both FF and IE:
$(document).ready(function(){ /*.code.*/ });
Or the short-hand form:
$(function(){ /*.code.*/ });
To add to Jonathans answer, jQuery's own documentation regarding $(document).ready:
"While JavaScript provides the load event for executing code when a page is rendered, this event does not get triggered until all assets such as images have been completely received. In most cases, the script can be run as soon as the DOM hierarchy has been fully constructed. The handler passed to .ready() is guaranteed to be executed after the DOM is ready, so this is usually the best place to attach all other event handlers and run other jQuery code. When using scripts that rely on the value of CSS style properties, it's important to reference external stylesheets or embed style elements before referencing the scripts."
source: http://api.jquery.com/ready/
EDIT:
Per your comments, it sounds like you are dependent on another javascript executing before you want your script to execute to grab the value. I can think of two options here:
1) If the other script is in your control, then have it invoke the code you want in your load() functions.
2) If this other code is not in your control, then your best best is to "observe" the field of interest for when it changes, so you know when to invoke your own script. I don't believe jQuery has this functionality built in (for non form fields), but there are plugins (such as http://plugins.jquery.com/taxonomy/term/1939).
精彩评论