Work on old websites yielded an interesting situation recently when an upgrade caused this JavaScript error in Chrome:
Uncaught TypeError: Object [object Object] has no method ‘createDocumentFragment’
The code worked flawlessly in Firefox and a review of the stack trace in Google’s Chromium 23 (along with testing unminified code) revealed that jQuery’s .find()
function was not returning kosher data. It turns out that both jQuery and MooTools were being used by plugins of this very outdated website. We are talking about Joomla 1.5, MooTools 1.1.2 and jQuery 1.3. As part of this upgrade, I migrated the site to jQuery 1.8 (yes, 1.9 is out and 2.0 is on the horizon). Switching from $()
to jQuery()
did not solve the problem, but simply bumping MooTools to 1.2.x seems to.
While testing, I found that this could be a suitable work-around in our situation if upgrading MooTools were not an option (I would have to replace the .find()
calls with .altFind()
):
$.fn.altFind = function(selector) {
var ret = this.find(selector);
// Yes, this is stupid. Got a better idea?
for (var x = 0; x < ret.length; x++) {
ret[x] = $(ret[x])[0];
}
return ret;
}
This wrapper for .find()
is a really goofy work-around since it just runs the faulty jQuery objects through jQuery again. Pick your poison. Either way, you now have another reason to prefer a custom solution with a standardized set of tools for your project.