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 trialAlasdair Marchant
4,592 PointsWhat is the event handler?
$(".spoiler").on("click", "button", function(alasdair){ console.log(alasdair); });
is the function(alasdair){}
the event handler?
how would I pass multiple arguments to this function? for example function(alasdair, param1, param2) - tried but this doesn't seem to work
1 Answer
Kevin Nguyen
1,317 PointsYou can try this one:
$(button).on('click', function(e) {
console.log(e);
console.log(e.target);
});
The event handler doesn't accept direct passing param. So you must try to define them inside a function:
$(button).on('click', function(e) {
var buttonText = $(this).html();
console.log(buttonText)
});
You are running jQuery. So that's enough. If you move to ES6, you should learn more about arrow function.