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 (2014) Creating a Simple Lightbox Perform: Part 1

function(event)

I am having trouble about the first parameter of the click function below: $("#imageGallery a").click(function(g){ g.preventDefault(); console.log(g); }

What I do not understand is that what's the special meaning of the first parameter of the anonymous function since "g" can be any parameters and we have not specified what "g" is. But why "g" can have "preventDefault" method? Or is there is anything special about the first argument of the function when I passed it into the click method? Thanks so much!

1 Answer

Steven Parker
Steven Parker
231,275 Points

Whatever you name it, the parameter given to the function in a click handler is the event object associated with the event being handled. One of the methods of an event object is "preventDefault".

While the name can be anything, it's more typical to name this argument "e".