JQuery on click with selector / data

Trying to understand the following syntax in my autocomplete plugin

    // Listen for click event on suggestions list:
    container.on('click.autocomplete', suggestionSelector, function () {
        that.select($(this).data('index'));
    });

      

Syntax

"click.autocomplete" I'm confused, there is no autocomplete class on this page, but it still works. what does ".autocomplete" mean here?

+3


source to share


1 answer


.autocomplete

there is no selector here, it's a namespace. The selector is contained in your variable suggestionSelector

. Handled an event click

in the namespace autocomplete

.

See jQuery event.namespace

and Custom Events documentation.



JQuery documentation page for its methodon()

:

.on( events [, selector ] [, data ], handler )

      

events
Type: String
One or more event types, separated by spaces, and optional namespaces such as "click" or "keydown.myPlugin".

+2


source







All Articles