May 2017
Intermediate to advanced
448 pages
10h 10m
English
Binding a handler for an event (such as a simple click event) is such a common task that jQuery provides an even terser way to accomplish it; shorthand event methods work in the same way as their .on() counterparts with fewer keystrokes.
For example, our style switcher could be written using .click() instead of .on() as follows:
$(() => { $('#switcher-default') .addClass('selected'); $('#switcher button') .click(function() { const bodyClass = this.id.split('-')[1]; $('body') .removeClass() .addClass(bodyClass); $('#switcher button') .removeClass('selected'); $(this) .addClass('selected'); }); });
Shorthand event methods such as the previous one exist for the other standard DOM events such as blur, keydown ...
Read now
Unlock full access