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 jQuery Basics Working with jQuery Collections Looping through a jQuery collection

$(event.target) Vs. $(this)

I'm not understanding the difference. They seem to do the same thing?

1 Answer

Steven Parker
Steven Parker
231,007 Points

In an event handler, they are often the same thing. If you define an event handler with a conventional function expression, the system will set "this" to the target of the event object.

But if you were to define your event handler using an arrow function, the value of "this" would reflect the execution context.

Thanks Steven Parker .... What do you mean by reflect the execution context?

Steven Parker
Steven Parker
231,007 Points

The "execution context" is where the in the code the definition occurred. See the MDN page for an example.