Skip to main content

Bug Tracker

Side navigation

#11130 closed bug (fixed)

Opened January 05, 2012 02:44PM UTC

Closed January 13, 2012 01:36AM UTC

Last modified March 09, 2012 08:19PM UTC

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) {
        // will report  instead of 
data = 'bar';
$(window).on(map, null, data).trigger('foo');

The problem exists on line null

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

Attachments (0)
Change History (4)

Changed January 05, 2012 02:47PM UTC by zzzzbov comment:1

I've created a jsFiddle for this issue:

Changed January 05, 2012 02:54PM UTC by rwaldron comment:2

component: unfiledevent
milestone: None1.7.2
owner: → rwaldron
priority: undecidedlow
status: newassigned

Confirmed. I'll look into this now

Changed January 05, 2012 03:33PM UTC by rwaldron comment:3

Changed January 13, 2012 01:36AM UTC by Rick Waldron comment:4

resolution: → fixed
status: assignedclosed

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

Changeset: c0da49ff37484764bd0f33fe40d1a5f83d0f39e8