Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check whether element is in document before calling jQuery.fn.offset() #5584

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/js/select2/dropdown/attachBody.js
Expand Up @@ -165,7 +165,15 @@ define([
$offsetParent = $offsetParent.offsetParent();
}

var parentOffset = $offsetParent.offset();
// As of jQuery 3.0, .offset() only works for elements that are currently
// in the document. In earlier versions, this would return the value below
// but in jQuery 3.0 this throws an error.
var parentOffset = {top: 0, left: 0};

// If the element is in the document we are safe to use .offset()
if(document.body.contains($offsetParent[0])) {
parentOffset = $offsetParent.offset();
}

css.top -= parentOffset.top;
css.left -= parentOffset.left;
Expand Down