How to add Chosen Plugin to dynamically created / cloned CSS div?

后端 未结 4 786
傲寒
傲寒 2020-12-04 02:42

The Chosen Plugin for jQuery (found here: http://harvesthq.github.com/chosen/ ) adds extra functionality to select HTML elements. I can add the functionality to the initial

4条回答
  •  萌比男神i
    2020-12-04 03:04

    Looking at the chosen source code it seems that you cannot just clone the selects that already has been chosen, as they already have their chzn-done class set, and chosen only applies to the selects that do not have this class set. That means your call to chosen on the new select effectively does nothing.

    The select appears as being chosen-enabled because you're cloning the entire group. That is, after call to clone new group already contains a chosen interface, and the select is already hidden. Of course, the chosen interface in the new group is not bound to the new select. Also, clicking on select does not change anything because jQuery.clone does not add new events by default.

    Basically, you should never use jQuery.clone to clone complex content (or, more specifically, you should not clone complex content at all). If you want to create a new input group with a new chosen-enabled select, just do it explicitly.

提交回复
热议问题