I’m unsure how to structure the following. This works fine:
$('.hover li').on 'hover', (ev) ->
$(this).addClass('active')
I know I can use ‘toggle’ instead of ‘addClass’, but for other reasons I need a handler out function passed. So I tried this:
$('.element').on 'hover', (ev)
-> $(this).addClass('active'),
-> $(this).removeClass('active')
This returns an error – ‘unexpected ,’. I’ve tried other variations, and most of the examples I’ve found online do not use the .on 'hover' (ev) -> format.
You cannot use
on()for this if you’d like to attach both event handlers at a time.You need to use
hover():or even better, utilizing
toggleClass()