3

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'));
    });

"click.autocomplete" syntax I am confused about, there is no class autocomplete on this page but it still works. what does the ".autocomplete" here refer to ?

1 Answer 1

2

.autocomplete here isn't a selector, it's a namespace. The selector is contained within your suggestionSelector variable. The event being handled is click within the autocomplete namespace.

See jQuery's event.namespace and Custom Events documentation.

jQuery's documentation page for its on() method states:

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

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.