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 Introduction to jQuery Events Using the on() Method

What is an Event Handler in jQuery?

From video: https://teamtreehouse.com/library/using-the-on-method

I'm not understanding what an event handler or an event is. Thanks!

2 Answers

Zakk George
Zakk George
4,550 Points

Basically an event handler is block of code waiting for an action to execute the code within. For example:

$( "#target" ).click(function() {
  alert( "Handler for .click() called." );
});

When the user clicks on the target that the listener was placed the code inside the function will run. It will run EVERY time the target is clicked.

I hope this helped clear it up slightly! Happy Hacking!

A nice, and simple explanation.

Rifqi Fahmi
Rifqi Fahmi
23,164 Points

So, is it the same as callback ???

ywang04
ywang04
6,762 Points

Event Handler is the call back function. Please refer to this course. https://teamtreehouse.com/library/listening-for-events-with-addeventlistener