#10132 closed bug (fixed)
.val(...) in change handler invokes change handler in IE
Reported by: | Owned by: | dmethvin | |
---|---|---|---|
Priority: | low | Milestone: | None |
Component: | event | Version: | 1.6.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
When you have a function bound the the change event of an input field, and the function changes the input field's value using .val(...), the change event handler gets invoked twice (once from the real change, and once from calling .val(...)). This happens in IE8 and IE9, but not in FireFox 6 or Chrome.
The expected output from the code below is that "change" will be logged once, however it actually gets logged twice in IE.
<!doctype html> <html> <head> <title>x</title> </head> <body> <input type="text" id="inputField" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> <script> $("#inputField").change(function() { console.log("change"); $(this).val("newval"); }); </script> </body> </html>
Change History (4)
comment:1 Changed 12 years ago by
Component: | unfiled → event |
---|---|
Priority: | undecided → low |
comment:2 Changed 12 years ago by
Owner: | set to dmethvin |
---|---|
Status: | new → assigned |
Since it's using the special event interface there may be a solution; I'll mark it open and look at it soon.
comment:3 Changed 12 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
This is fixed by the new IE change detection logic in 1.7.
https://github.com/jquery/jquery/commit/3bd7bed340f9077d39734ffce366ef2caeb9ce35
http://jsfiddle.net/timmywil/apH9c/
Confirmed, but I'm not sure we can fix this. Changing the value with javascript triggers a change in IE, but not in other browsers.