bootstrap-multiselect icon indicating copy to clipboard operation
bootstrap-multiselect copied to clipboard

Observing Classes

Open zaxwebs opened this issue 4 years ago • 1 comments

Is there a way to make this work with dynamically added classes? As in, if elements with a class are dynamically added to the page? E.g .multiselect for product selector that's added to the page after a 'Add product' button click?

zaxwebs avatar Feb 14 '21 06:02 zaxwebs

Not really. You would need to call .multiselect() on the newly-added content, or have something like:

function reinitMultiSelect(selector) {
    // Remove all existing multiselects
    $(selector).multiselect('destroy');

    // Apply plugin to all matching elements
    $(selector).multiselect();
}

You'd call this after whatever code adds your new select elements. You're probably better off just applying the plugin to only your new content, though, as something like that example could be quite memory and/or CPU intensive, if you have a lot of selects on the page.

tiesont avatar Feb 14 '21 23:02 tiesont