Bug Tracker

Opened 10 years ago

Closed 10 years ago

#13832 closed bug (wontfix)

$("html").parent() differs from $("html").parents()

Reported by: jbedard Owned by:
Priority: high Milestone: 2.next
Component: traversing Version: 1.9.1
Keywords: Cc:
Blocked by: Blocking:


$("html").parent()[0] === document
$("html").parents()[0] === undefined

The documentation implies that these methods follow the same definition of "parent" so I would suspect they should treat <html>/document the same?

Looking at the latest 2.0 source... $.dir checks "elem.nodeType !== 9" while traversing and only processes "nodeType === 1", where $.fn.parent only checks "parent.nodeType !== 11". It looks like $.fn.parent should instead check "parent.nodeType === 1"?

Change History (4)

comment:1 Changed 10 years ago by dmethvin

Milestone: None2.0.1
Status: newopen

Agreed, thanks!

comment:2 Changed 10 years ago by dmethvin

Component: unfiledtraversing
Milestone: 2.0.12.next
Priority: undecidedhigh

Discussed at the 2013-04-29 meeting, there is concern about changing this because it's been this way (inconsistent) forever. Seems that .parent() should always return its parent else we'll think the element is not connected. That makes it more likely we'd change .parents() but it would mean that the document would be added to the list where it isn't there today.

Last edited 10 years ago by dmethvin (previous) (diff)

comment:3 Changed 10 years ago by jbedard

Thanks for the update.

It seems weird returning a non element node since no other traversal methods do, but it does follow the definition of Node.parentNode.

If .parents() changes then .closest() should probably also change. Are there any others?

If .parent() remains as it is that would bring me back to the original reason I found this: $(document).css("...") crashes. I assumed this was because wrapping the document wasn't supported and .parent() shouldn't return it, but if any traversal methods return it then other methods should support it.

comment:4 Changed 10 years ago by dmethvin

Resolution: wontfix
Status: openclosed

Making this a docs ticket, given how long it's been like this it is going to break code to "fix" it.


Note: See TracTickets for help on using tickets.