O'Reilly logo

Instant typeahead.js by Toby Osbourn

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 custom events (Become an expert)

On the modern web, events do not happen in isolation and, as developers, we want to be able to get our hooks into events at various stages. Luckily for us, typeahead.js offers plenty of scope for creating custom events and I will be discussing them in this section.

Getting ready

In order to show this functionality we can build on an existing example. I will use the third recipe, Preloading JSON (Should know). If we load up these files in our editors, we will be specifically adding to custom.js.

How to do it...

We want to hook into jQuery's .on functionality, which listens for events being triggered. We will call one for each of the publicly accessible events that are currently supported by typeahead.js.

When ...

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