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 JavaScript and the DOM (Retiring) Traversing the DOM Using previousElementSibling and insertBefore

Brian Patterson
Brian Patterson
19,588 Points

I am a bit confused

I have a few questions about this function.

listUL.addEventListener('click', (event) => {
    //this saying the if the html element is button
    if (event.target.tagName == 'BUTTON') {
      //if the class name is 'remove'.
      if (event.target.className == 'remove'){
        //I am unsure what this means.
      let li = event.target.parentNode;
      //I am unsure what this means.
      let ul = li.parentNode;
      //this removes the child
      ul.removeChild(li);
    }

1 Answer

Steven Parker
Steven Parker
231,271 Points

Does this clear it up?

let li = event.target.parentNode; :point_left: get the list item (li) element that this button is in
let ul = li.parentNode; :point_left: get the unordered list (ul) that the list item is in

Brian Patterson
Brian Patterson
19,588 Points

Brilliant Steven. Can give me any tips on how best to learn about the DOM.

Steven Parker
Steven Parker
231,271 Points

I really enjoyed the course you're taking right now. There's also DOM Scripting By Example.