internet explorer - IE 9 jQuery error: "Object doesn't support ... 'on'"? -
i need help. i'm getting following error in ie9. code working in firefox:
script438: object doesn't support property or method 'on' this raised on following code:
$(function() { $(document).on('change', '#dropdownval select', function(event) { //logic function }); });
works in firefox, not ie?
i make sure both browsers loading same source. honest, it's bit impossible firefox use .on while using jquery 1.6, since method didn't exist.
within console (f12 developer tools in ie , firebug in firefox) type following:
jquery.fn.jquery this should resturn current version of jquery loaded on particular page. instance, of today, running command here on stackoverflow results in "1.7.1". secondly, test presence of .on method, can access without parenthesis, using double-negation cast true boolean:
!!jquery.fn.on // true if .on present, false otherwise with jquery 1.6, use .delegate rather .on
since you're using jquery 1.6, don't have access .on method, introduced in jquery 1.7. appropriate fallback use .delegate method instead, or upgrade latest version of jquery (microsoft cdn, google cdn, jquery cdn).
the syntax .delegate follows of .on pretty closely:
$("#dropdownval").delegate("select", "change", function(event){ alert( $(this).val() ); }); fiddle: http://jsfiddle.net/jonathansampson/rmbn4/
if decide upgrade...
you close .on code, don't want bind event far down document object - mean event need propagate potentially long distance before being handled. instead, did .delegate example, we'll bind closer select element:
$("#dropdownval").on("change", "select", function(event){ alert( $(this).val() ); }); fiddle: http://jsfiddle.net/jonathansampson/rmbn4/1/
you'll note main difference between 2 order of first 2 parameters chained method. .delegate, selector precedes event. .on, order reversed.
Comments
Post a Comment