Bug Tracker

Opened 7 years ago

Closed 7 years ago

#12686 closed bug (wontfix)

Live change event is not fired on IE8 when input is focused

Reported by: joachim.e.rousseau+jquery@… Owned by: elgreg
Priority: high Milestone: None
Component: event Version: 1.8.2
Keywords: ie7 ie8 Cc:
Blocked by: Blocking:

Description

When 'change' event is bound whith jQuery.live() on a text input that has focus (carret blinking inside, focus() explicitly called), the 'change' event isn't fired on first value change.

I just added an explicit focus an an example from bug #5851 to show this one.

Expected behaviour (FF/Chrome OK) : when DOM is ready, the text input has focus. If you start typing text then leaving it whith tab or clicking outside, the alert shows.

IE8 (KO) behaviour : when DOM is ready, the text input has focus BUT if you start typing text then leaving it, no alert is visible. To get the alert, you have to get back into the text field then modify its value, then leaving it again.

Reported against jQuery 1.7.2 and 1.8.2.

Change History (7)

comment:1 Changed 7 years ago by anonymous

Don't know how to attache the example, here is the code :

<html>
  <head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
    <script>
      jQuery(function() {
      	jQuery('#txt0')[0].focus()
        $('.textbox').live('change', function (event) {
          alert("Changed!");
        });
      });
    </script>
  </head>
  <body>
    <input id="txt0" type="text" class="textbox"/>
  </body>
</html>

comment:2 Changed 7 years ago by dmethvin

Keywords: ie7 ie8 added
Status: newopen

Confirmed in IE8: http://jsfiddle.net/VUY3g/

Works in bare DOM: http://jsfiddle.net/VUY3g/1/

Or bare DOM with jQuery loaded: http://jsfiddle.net/VUY3g/2/

Or with attachEvent instead of DOM0 handler: http://jsfiddle.net/VUY3g/3/

comment:3 Changed 7 years ago by dmethvin

Clarifying ... the event is firing, but for these cases we need to manually bubble and we're not for some reason.

comment:4 in reply to:  3 Changed 7 years ago by anonymous

Replying to dmethvin:

Clarifying ... the event is firing, but for these cases we need to manually bubble and we're not for some reason.

Yes, I forgot to mention it works with bind() and on() without delegate. The handler is not called only if bound with live() or on() with delegate, and only for the very first change.

comment:5 Changed 7 years ago by timmywil

Component: unfiledevent
Priority: undecidedhigh

comment:6 Changed 7 years ago by elgreg

Owner: set to elgreg
Status: openassigned

comment:7 Changed 7 years ago by elgreg

Resolution: wontfix
Status: assignedclosed

Took a look at this with @dmethvin. The internals of jquery spoofing event bubbling for change events in old IE mean you need to focus after attaching the live event. Simply moving the focus to after the event is attached should fix the issue:

jsfiddle: http://jsfiddle.net/elgreg/6jrU3/

Marking as won't fix as generally a delegated event can generally be attached prior to focus.

Note: See TracTickets for help on using tickets.