Bug Tracker

Opened 7 years ago

Closed 7 years ago

#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:
Blocked by: Blocking:

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 (2)

comment:1 Changed 7 years ago by anonymous

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

comment:2 Changed 7 years ago by dmethvin

Resolution: cantfix
Status: newclosed

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.

Note: See TracTickets for help on using tickets.