Ticket #4534 (closed bug: invalid)
2 instances of jQuery kills unbind
| Reported by: | ptarjan | Owned by: | |
|---|---|---|---|
| Priority: | major | Milestone: | 1.4 |
| Component: | unfiled | Version: | 1.3.2 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
Steps to recreate :
- http://paul.slowgeek.com/nodeSelector/dev/bad-unbind.html
- Click the "Add key listener"
- Press keys and notice they are printed
- Press ESC and see it says "unbinding"
- Press more keys and see they AREN'T printed
- Click the "add key listener" again
- Press keys and see they ARE printed
- Press ESC and see it says "unbinding"
- Press keys and see they ARE printed (this is the bad part)
If I change the javascript code to NOT add the jQuery library, then it works as expected.
Pasting Code incase my site is down:
--- bad-unbind.html <a href=' javascript:(
function() {
var s=document.createElement("script");
s.charset="UTF-8"; s.src="bad-unbind.js";
document.body.appendChild(s)
})();
'>Add key listener</a> <p id='key'></p> --- end
--- bad-unbind.js addLibs = function () {
if (typeof(document.body) == "undefined" document.body == null) { setTimeout(addLibs, 100); return;
}
This line makes it work if (typeof($) == "undefined") {
node = document.createElement("script"); node.src = " http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"; document.body.appendChild(node);
} addEvents();
}
addEvents = function () {
if (typeof($) == "undefined" $("*") == null) { setTimeout(addEvents, 100); return;
} var keydown = function(e) {
if (e.keyCode == undefined && e.charCode != undefined) e.keyCode = e.charCode; $("#key").html("keydown " + e.keyCode); Escape key if (e.keyCode == 27) {
$("#key").html("unbinding"); $(document).unbind("keydown", keydown);
}
}; $(document).keydown(keydown);
} addLibs(); --- end
Change History
comment:2 Changed 3 years ago by dmethvin
- Status changed from new to closed
- Resolution set to invalid
It's okay to load two copies of jQuery, for example two different versions. However, at least one of them would need to use jQuery.noConflict() so that they could each be referenced. Loading two copies where the second clobbers the first doesn't make sense.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

The fix is don't include jQuery twice. I don't think jQuery needs to support itself getting loaded twice.