Skip to main content

Bug Tracker

Side navigation

#8821 closed bug (worksforme)

Opened April 08, 2011 09:46AM UTC

Closed April 11, 2011 03:09PM UTC

Javascript error is thrown in IE when executing closest(':visible')

Reported by: oldcrane@gmail.com Owned by: oldcrane@gmail.com
Priority: low Milestone: 1.next
Component: selector Version: 1.5.2
Keywords: Cc:
Blocked by: Blocking:
Description

Javascript error in IE 8 when executing element.closest(':visible');

Condition to recreate the defect:

1. browser: IE only (works fine on FF, Safari, Chrome)

2. target html object does not exist

3. ancestor of the element is not part of html DOM tree

  • created by document.createElement("div") or
  • child of element #abc which has been removed by $("#abc").empty()

Root cause:

property parentNode of the above ascestor element is different in different browser:

  • FireFox: 3.6.12 null
  • IE 8: an element with nodeName "#document-fragment" (value of parentElement is null)

Because jQuery uses following codes to get parent node in closest() method:

  • cur = cur.parentNode;

And following codes to check whether the element is visible:

  • (!jQuery.support.reliableHiddenOffsets && (elem.style.display | | jQuery.css( elem, "display" )) === "none")

Because the document fragment element does not have style property, exception will be thrown.

It is found in jQuery 1.4.4, and is also there in 1.5.2

Attachments (0)
Change History (3)

Changed April 08, 2011 01:56PM UTC by addyosmani comment:1

owner: → oldcrane@gmail.com
status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a reduced test case on http://jsFiddle.net that reproduces the issue experienced to help us assess your ticket!

Additionally, test against the jQuery (edge) version to ensure the issue still exists.

Changed April 11, 2011 02:04PM UTC by oldcrane@gmail.com comment:2

status: pendingnew

Test case created: http://jsfiddle.net/Crane/Y6Ujk/

Test result (IE 6.0.2900)

  • JS Error with jQuery 1.5.1
  • Works fine with jQuery (edge) :-)

Changed April 11, 2011 03:09PM UTC by rwaldron comment:3

component: unfiledselector
priority: undecidedlow
resolution: → worksforme
status: newclosed

If it's working on edge, then the issue is resolved. Closing.