Bug Tracker

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#11130 closed bug (fixed)

jQuery.fn.on: binding map with null selector ignores data

Reported by: zzzzbov Owned by: rwaldron
Priority: low Milestone: 1.7.2
Component: event Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:


Here's an example that will fail

var map,
map = {
    'foo': function (e) {
        //e.data will report `null` instead of `"bar"`
        console.log('data', e.data);
data = 'bar';
$(window).on(map, null, data).trigger('foo');

The problem exists on line 3674

on: function( types, selector, data, fn, /*INTERNAL*/ one ) {
    var origFn, type;

    // Types can be a map of types/handlers
    if ( typeof types === "object" ) {
        // ( types-Object, selector, data )
        if ( typeof selector !== "string" ) { //3674
            // ( types-Object, data )
            data = selector;
            selector = undefined;

It should probably read:

if ( typeof selector !== "string" && selector !== null ) {

Alternatively the docs need to be updated to address this difference:


selector A selector string to filter the descendants of the selected elements that will call the handler. If the selector is null or omitted, the handler is always called when it reaches the selected element.

Should be changed to say:

If the selector is an empty string or omitted

Change History (4)

comment:1 Changed 5 years ago by zzzzbov

I've created a jsFiddle for this issue:


comment:2 Changed 5 years ago by rwaldron

  • Component changed from unfiled to event
  • Milestone changed from None to 1.7.2
  • Owner set to rwaldron
  • Priority changed from undecided to low
  • Status changed from new to assigned

Confirmed. I'll look into this now

comment:4 Changed 5 years ago by Rick Waldron

  • Resolution set to fixed
  • Status changed from assigned to closed

Fix #11130: Don't neglect the data arg when event-map is passed.

Changeset: c0da49ff37484764bd0f33fe40d1a5f83d0f39e8

Note: See TracTickets for help on using tickets.