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 One Solution

Add the class "strike" to the restaurant name each time it's double clicked. Use event delegation on the ul element to l

Hello, when I write:

$('ul').on('dblclick', 'li', (event) => { $(event.target).addClass('strike');
});

Everything is working perfectly. But when I write:

$('ul').on('dblclick', 'li', () => { $(this).toggleClass('strike');
});

It doesn't work anymore. The toggleClass doesn't change the CSS of the li element... What am I doing wrong?

Thanks!

1 Answer

Adam Beer
Adam Beer
11,314 Points

Change your () => {} to function() => {}. I think now your code is working fine.

Huh, I ran into the same issue. Adam, any idea why the arrow syntax doesn't work?

Adam Beer
Adam Beer
11,314 Points

I just have tips. Maybe the babel doesn't translate the code to es5, or your browsers doesn't support the es6 codes.