I am having trouble with several jQuery plugins that add to jQuery.prototype ($.fn) not working in Internet Explorer 11 until after a page refresh. I believe the following illustrates the source of the trouble:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>foobar</title>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script>
$(function(){
var outside_jQuery = jQuery();
jQuery.prototype.foo = function(){};
$('pre').append('foo in outside_jQuery on load? '
+ ('foo' in outside_jQuery).toString());
$('input').on('click', function(){
$('pre').append('\nfoo in outside_jQuery on click? '
+ ('foo' in outside_jQuery).toString());
$('pre').append('\nfoo in jQuery() on click? '
+ ('foo' in jQuery()).toString());
});
});
</script>
</head>
<body>
<input type="button" value="foo?" />
<pre></pre>
</body>
</html>
In Firefox 26, after clicking the button the output is as follows, as expected:
foo in outside_jQuery on load? true
foo in outside_jQuery on click? true
foo in jQuery() on click? true
In Internet Explorer 11, after clicking the button the output is as follows:
foo in outside_jQuery on load? true
foo in outside_jQuery on click? true
foo in jQuery() on click? false
However, after refreshing the page once, it works as expected.
It seems like the changes to jQuery.prototype are not reflected in new jQuery objects created within the event handler, until after a page refresh. Why?