d1du
d1du

Reputation: 314

What does colon mean in jQuery when used inside of .trigger?

I looked at http://api.jquery.com/trigger/ and the examples did not answer my question. I am looking at some code and would like to know what this block of code is doing.

$(document).on('click', '#SubmitQuery', function(event) {
            event.preventDefault();
            $(document).trigger('filter:submit');
        });

Specifically, what does the colon inside of that trigger function do? For complete context, here is what filter is (I assume that the 'filter' inside of the trigger function refers to that filter object):

var filter = {
    init: function() {
        $(document).on('keypress', '#Filter', debounce(function(event) {
            if (event.keyCode == 13) {
                $(document).trigger('filter:text');
            }
        }, 300));

        $(document).on('click', '#ClearFilter', function(event) {
            event.preventDefault();
            $('#FilterText').val('');
            $('#FilterText').focus();
            $(document).trigger('filter:clear');
        });

        $(document).on('change', '.filterSection [type=checkbox]', function(event) {
            var group = $(this).parents('[data-filter-group]').attr('data-filter-group');
            var $checkboxes = $('[data-filter-group=' + group + '] [type=checkbox]');

            if ($checkboxes.length > 0) {
                if ($checkboxes.filter(':checked').length === 0) {
                    $(this).prop('checked', true);
                }
            }
        });

        $(document).on('click', '#SubmitQuery', function(event) {
            event.preventDefault();
            $(document).trigger('filter:submit');
        });

        $("#Filter").focus();
    }
};

Upvotes: 3

Views: 2054

Answers (1)

Tokiin
Tokiin

Reputation: 104

The colons specifies custom events, essentially creating namespaces for events you can call later without overriding default events or having to create multiple listeners on the same event.

You can find more information here: https://learn.jquery.com/events/introduction-to-custom-events/

Upvotes: 3

Related Questions