Reputation: 68680
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script>
<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.
Upvotes: 1
Views: 87
Reputation: 1038900
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.
Upvotes: 5
Reputation: 32117
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
});
Upvotes: 0
Reputation: 2592
Two options for what you're trying to achieve:
$(function() { alert('works'); });
$(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.
Upvotes: 0
Reputation: 272146
It should work after all images, css and scripts are loaded. Is there something that is taking too long to load?
Upvotes: 1