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 trialMing Chi Wong
2,909 PointsWhat is an element sibling?
I don't quite understand what an element sibling is?
Ming Chi Wong
2,909 PointsThanks a lot! This helped me a lot!
Ming Chi Wong
2,909 PointsDoes previousSibling exist that is used in the video?
2 Answers
Steven Parker
231,248 PointsA "sibling" is any other element that is in the same container. For example, all the option
elements inside a select
are siblings.
The "previousSibling" is the sibling that comes just before the current item. Note that this is a node-based term so you may prefer to use "previousElementSibling" instead in most cases. This guarantees a reference to another element and not something like a text node.
Ming Chi Wong
2,909 PointsTheres another part of the video where I don't understand.
let li = event.target.parentNode;
let ul = li.parentNode;
ul.removeChild(li);
Isn't <li> meant to be a child node?
I don't quite understand this part? ---> let li = event.target.parentNode;
Steven Parker
231,248 PointsThe <li> is both a parent and child. It's a child of the <ul>, but it's the parent to the element that caused the event. That element is inside the <li>.
Dylan Glover
2,537 PointsDylan Glover
2,537 PointsSibling elements are elements that share the same parent. For example all of the <li> within a <ul> would be siblings of each other.
Hope this helps!