FAQ: Traversing the DOM - Closest

This community-built FAQ covers the “Closest” exercise from the lesson “Traversing the DOM”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

Introduction to jQuery

FAQs on the exercise Closest

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Hello, I’ve got a side question regarding word this used in this exercise.

I have seen that it has been used in some part of the code, thus why it is working in one place and not in another?

This is the example in have found in Learn window:

$('.choice').on('click', event => {
  $(this).siblings().removeClass('selected');
  $(event.currentTarget).addClass('selected');
});

Then I have tried to change event.currentTarget to this from main.js and it doesn’t make any effect.

$('.shoe-details li').on('click', event => {
    $(event.currentTarget).addClass('active');
    $(event.currentTarget).siblings().removeClass('active');
  });

Why it is working in one place and it is not in another? What is the rule here to use this?

I think someone in a previous community forum page suggested using (event.currentTarget) instead of (this) as proper syntax