Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

brandonlind2
brandonlind2
7,823 Points

Is there a difference between a parent.node and a parent in a dom tree?

I read "Inherits properties from its parents Node, and its own parent, EventTarget, and implements those of ParentNode, ChildNode, NonDocumentTypeChildNode, and Animatable."

The first part makes it sound like they're different, which is a bit confusing, because in a dom tree all children are nested within their parent, so wouldn't all parents be nodes? Are they the same or am I not understanding something correctly?

1 Answer

jsdevtom
jsdevtom
16,963 Points

"The jQuery .parent() selector selects the immediate parent of all the nodes in the node set. However, since in your example the node set is just one node $(this), there's little practical difference.

This difference matters if you were to do something like $(".foo").parent(), where there might be many nodes that have the class foo."

Source: http://stackoverflow.com/questions/9948171/parent-vs-parentnode