I am attempting to understand the ‘load’ event in jQuery as described here: http://api.jquery.com/load-event/. So far, I have been unable to get it triggered even once!
Here is some sample code. The only console message that turns up is “DOM READY” -not a single load call. Replacing calls to .load() with .bind(‘load’,..) does not make any difference.
<!DOCTYPE html>
<html>
<head>
<script src="lib/jquery.min.js"></script>
<script>
$(function(){
console.log("DOM READY");
});
$(document).load(function(){
console.log("Document Loaded");
});
$('#foo').load(function(){
console.log("foo loaded");
});
$('#bar img').load(function(){
console.log('image loaded');
});
$('#bar').load(function(){
console.log('bar loaded');
});
</script>
</head>
<body>
<div id="foo">Hellow world</div>
<div id="bar">
<img src="pics/pig.png"/>
</div>
</body>
</html>
What am I doing wrong?
If you use the document.ready event to do your bindings, you are guaranteed that elements exist: