O'Reilly logo

Mastering jQuery by Alex Libby

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating and decoupling custom event types

If you've spent any time developing jQuery, then I am sure you are more than familiar with the standard event types that we can use, such as .click(), .hover(), or .change().

These all serve a useful purpose, but all have one thing in common – we're a bit limited in what we can do with them! Our code will be dictated by the extent of what these handlers can do. What if we can break this limitation, and create any type of custom event handler?

Of course, we can always combine multiple events together, to be served by the same function:

$('input[type="text"]').on('focus blur', function() {
  console.log( 'The user focused or blurred the input' );
});

But this is still limited to those event handlers that are ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required