tags:

views:

56

answers:

5
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"&gt;&lt;/script&gt;
<script type="text/javascript">
    alert('works');
</script>
<script type="text/javascript">
    $(window).load(function () {
        alert('does not work');
    });
    ​
</script>

Very strange, I'm not sure why it isn't working.

+5  A: 

I think the function should be .ready() and not .load() (this sends an AJAX request):

$(window).ready(function () {

Also make sure you understand the distinction between $(document).ready and $(window).ready. The first will be triggered when the DOM is ready while the second when the DOM and all images are ready.

Darin Dimitrov
[load-event](http://api.jquery.com/load-event/)
Reigel
@Reigel, you are correct. Didn't know this event existed.
Darin Dimitrov
A: 

Are you looking for this:

$(function() {
    alert("does work");
});
Bobby
+1  A: 

It should work after all images, css and scripts are loaded. Is there something that is taking too long to load?

Salman A
A: 

Two options for what you're trying to achieve:

  1. $(function() { alert('works'); });

  2. $(document).ready(function() { alert('works'); });

It's up to you which one you use. Personally I prefer the shorthand code in option 1 but there's a readability advantage with the second option.

chigley
A: 

youe are doing window.load which waits for every thing to get loaded before executing. however you should use DOM ready function of jQuery.

jQuery(function(){
    //do something
});
Praveen Prasad