harvesthq/chosen — Issue #389: Various functionality broken when target element not attached to DOM
Author: elliterate
Created: 2011-12-09 19:56:47+00:00
State: open

We're using Chosen in our application and using Jasmine to test the integration with the rest of our JavaScript. We're trying to keep as much of our JavaScript independent of the DOM as possible, which we ensure by testing it while detached, but we've run into a few cases where Chosen expects it to be in the DOM.

One such example is issue #358.

Another example is trying to click the "close" button on a multi-select choice. The lookup and subsequent click event bind rely on the button being in the DOM. To fix it, we had to modify line 596 of `chosen.jquery.js` (v0.9.5) from this:

link = $('#' + choice_id).find("a").first();

to this:

link = this.container.find('#' + choice_id).find("a").first();

It would seem that the general solution to these issues is to switch, whenever possible, from this:

$('...')

to this:

this.container.find('...')