Bug Tracker

Opened 9 years ago

Closed 9 years ago

#8821 closed bug (worksforme)

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

Reported by: oldcrane@… Owned by: oldcrane@…
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

Change History (3)

comment:1 Changed 9 years ago by addyosmani

Owner: set to oldcrane@…
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.

comment:2 in reply to:  1 Changed 9 years ago by oldcrane@…

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) :-)

comment:3 Changed 9 years ago by Rick Waldron

Component: unfiledselector
Priority: undecidedlow
Resolution: worksforme
Status: newclosed

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

Note: See TracTickets for help on using tickets.