Search code examples
eventsjquerylive

Strange behavior using live event on IE10 with jQuery


I have the following code:

$('input.test2').live('keyup', function (e) {
});

$('input.test1').live('change', function (e) {
});

test1 and test2 are classes of the same input element.. but only the test1 is triggered.

Can somebody explain to me why this is happening? (It only happens on IE10). I tried to return false or e.stopPropagation() but nothing changed.


Solution

  • Try using "on" instead of "live"

    $('input.test1').on('change', function (e) {
    });
    
    $('input.test2').on('keyup', function (e) {
    });
    

    As per the jQuery docs:
    http://api.jquery.com/live/

    "As of jQuery 1.7, the .live() method is deprecated. Use .on() to attach event handlers. Users of older versions of jQuery should use .delegate() in preference to .live()."