The invocation context (this) of the forEach function call

MDN states: array.forEach(callback[, thisArg]) If a thisArg parameter is provided to forEach, it will be used as the this value for each callback invocation as if callback.call(thisArg, element, index, array) was called. If thisArg is undefined or null, the this value within the function depends on whether the function is in strict mode or not … Read more

‘this’ does not work properly in another event. I’m clueless as to why [duplicate]

You aren’t attaching the event handler correctly. This line: $(‘.figure’).click(toggleCarousel(this)); …is calling toggleCarousel with this immediately (that’s what the parens will do). What you really want is to pass the function object to .click(): $(‘.figure’).click(toggleCarousel); Update: As @FelixKling pointed out, you’ll also want to pass the target of the event to the downstream functions; it … Read more