Bug Tracker

Opened 11 years ago

Closed 11 years ago

#11820 closed bug (cantfix)

Event error does not attach to future elements with .on();

Reported by: [email protected] Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.2
Keywords: Cc:
Blocked by: Blocking:


The using the on() method does not properly bind future elements when firing the "error" event type checked against recent and git repository

<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
$('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" />');

<!-- element src will fail triggering error event -->
<!-- error will be caught by $(img).on('error'); -->
<img src="image.gif" width="100px" />

Change History (2)

comment:1 Changed 11 years ago by anonymous

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

comment:2 Changed 11 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.


I've updated the documentation for the .on() method to clarify this.

Note: See TracTickets for help on using tickets.