We just upgraded our jQuery version from v1.7 to v3.4.1. We have code which passes a jQuery object (which doesn't yet exist in the DOM, and I'm guessing is the root cause of this problem) to a function. However, when attempting to handle this newly created variable, it only returns the root jQuery function itself: jQuery.fn.init {}
This SO answer helped me realize the issue: Help understanding jQuery's jQuery.fn.init Why is init in fn
Actual Snippet:
create: function (params) {
console.log('params.target:', params.target);
var $target, id;
if (_.isString(params.target)) {
if (params.target.charAt(0) === '#') {
$target = $('#send-to-friend-dialog');
console.log('$target1: ', $target);
} else {
$target = $('#' + params.target);
}
} else if (params.target instanceof jQuery) {
$target = params.target;
} else {
$target = $('#dialog-container');
}
console.log('$target.length: ', $target.length)
// if no element found, create one
if ($target.length === 0) {
console.log('$target2 : ', $target);
if ($target.selector && $target.selector.charAt(0) === '#') {
id = $target.selector.substr(1);
$target = $('<div>').attr('id', id).addClass('dialog-content').appendTo('body');
}
}
// create the dialog
console.log('$target3: ', $target);
this.$container = $target;
this.$container.dialog($.extend(true, {}, this.settings, params.options || {}));
return this.$container;
},
Output in v1.12.4: https://i.stack.imgur.com/DkPtx.png
Output in v3.4.1: https://i.stack.imgur.com/2PgWR.png
So while it is defined, the object itself is a very different output in both versions and I'm wondering why?
Thank you!