May 2017
Intermediate to advanced
448 pages
10h 10m
English
We need to make our .off() call more specific so that it does not remove both of the click handlers we have registered. One way of doing this is to use event namespacing. We can introduce additional information when an event is bound that allows us to identify that particular handler later. To use namespaces, we need to return to the non-shorthand method of binding event handlers, the .on() method itself.
The first parameter we pass to .on() is the name of the event we want to watch for. We can use a special syntax here, though, that allows us to subcategorize the event:
$(() => { $('#switcher') .on('click.collapse', (e) => { if (!$(e.target).is('button')) { $(e.currentTarget) .children('button') .toggleClass('hidden'); ...Read now
Unlock full access