Am going through the event handling in jquery from the website : jquery events documentation
I have having trouble in replicating jquery error event in my page.
HTML
<!DOCTYPE html>
<html>
<head>
<title>User Registration</title>
</head>
<body>
<div id="header">
<img id="register" src="../image/register1.jpg" />
</div>
<script type="text/javascript" src="../js/jquery-1.11.1.js"></script>
<script type="text/javascript" src="../js/registerForm.js"></script>
</body>
</html>
i have a file register.jpg in the image folder. i deliberately gave register1.jpg to check if the error occurs. When i go to chrome developer tools, i could find the error.
but my jquery code is not sensing the error . i want to load up and alternative image if the first image is not loaded, as given in the documentation example. But , even the alert message is not getting displayed on the error. Please help.
jQuery Code :
$("img").error(function(){
alert("Error Loading Image");
$(this).hide();
});
scriptelement in body?) … by the time you bind the event handler, the event has already fired.