Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#11130 closed bug (fixed)

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

Reported by: zzzzbov Owned by: Rick Waldron
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 11 years ago by zzzzbov

I've created a jsFiddle for this issue:


comment:2 Changed 11 years ago by Rick Waldron

Component: unfiledevent
Milestone: None1.7.2
Owner: set to Rick Waldron
Priority: undecidedlow
Status: newassigned

Confirmed. I'll look into this now

comment:4 Changed 11 years ago by Rick Waldron

Resolution: fixed
Status: assignedclosed

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

Changeset: c0da49ff37484764bd0f33fe40d1a5f83d0f39e8

Note: See TracTickets for help on using tickets.