Side navigation
#11820 closed bug (cantfix)
Opened May 26, 2012 01:08AM UTC
Closed May 26, 2012 01:18AM UTC
Event error does not attach to future elements with .on();
Reported by: | dicetrash@gmail.com | 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>
Attachments (0)
Change History (2)
Changed May 26, 2012 01:16AM UTC by comment:1
Changed May 26, 2012 01:18AM UTC by comment:2
resolution: | → cantfix |
---|---|
status: | new → closed |
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.
Sorry did not read paste guide before posting
http://jsfiddle.net/7cnGd/