Skip to main content

Bug Tracker

Side navigation

#13567 closed bug (notabug)

Opened March 05, 2013 03:29PM UTC

Closed March 05, 2013 03:39PM UTC

error in .map() when callback returns a jQuery object

Reported by: Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: git
Keywords: Cc:
Blocked by: Blocking:
Description -- jQuery 1.9.1

var $opts = $('.plant-page').map(function (i, el) {
    return $('<option>');
}).appendTo('#change-page select');

error is: "Uncaught TypeError: Cannot read property 'ownerDocument' of undefined"

When I switch to jQuery 1.8.3, result is as expected -- the option elements are appended to the select:

in jQuery 1.9.1, if I rewrite the .map() callback function to return a DOMelement instead of a jQuery object, it works as expected:

var $opts = $('.plant-page').map(function (i, el) {
    return $('<option>').text([0];
}).appendTo('#change-page select');

The documentation at doesn't seem to say that the callback function may not return jQuery objects, so I'm not sure if this is a bug in 1.9 or a reversion to intended behavior (which should be clarified in the documentation).

Attachments (0)
Change History (1)

Changed March 05, 2013 03:39PM UTC by dmethvin comment:1

resolution: → notabug
status: newclosed

You are trying to append a jQuery object that is inside a jQuery object, since you inserted a jQuery object into said jQuery object via the $ This is not supported, but obvious enough. We generally don't make a list of everything that cannot be in a jQuery set because there is an infinite list of possibilities for doing it wrong. Your rewrite looks better.