Modify ↓
Ticket #11820 (closed bug: cantfix)
Event error does not attach to future elements with .on();
| Reported by: | dicetrash@… | Owned by: | |
|---|---|---|---|
| Priority: | undecided | Milestone: | None |
| Component: | unfiled | Version: | 1.7.2 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
The using the on() method does not properly bind future elements when firing the "error" event type checked against recent and git repository
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-git.js" ></script>
<script type="text/javascript">
$(document).ready(function() {
$('body').on('error', 'img', function(err_event) {
//this will never fire but i feel as though it should
console.log('wont fire anyway'); //errors do not bubble
});
$('body').on('click', 'img', function(ev) {
//clicks bubble correctly and bind to future elements
console.log($(this));
});
$('img').on('error', function(err_event) {
//does not bind to future elements
//but is called once for pre-created element
console.log(['old element', this]);
});
$('body').append('<img src="image.gif" />');
});
</script>
</head>
<body>
<!-- element src will fail triggering error event -->
<!-- error will be caught by $(img).on('error'); -->
<img src="image.gif" width="100px" />
</body>
</html>
Change History
comment:2 Changed 13 months ago by dmethvin
- Status changed from new to closed
- Resolution set to cantfix
Error events on images don't bubble. There is no good way to fake this one either.
http://www.w3.org/TR/DOM-Level-3-Events/#event-type-error
I've updated the documentation for the .on() method to clarify this.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
Note: See
TracTickets for help on using
tickets.

Sorry did not read paste guide before posting http://jsfiddle.net/7cnGd/