Destroy


The method .destroy() can be used to remove the initialized HTML node in the DOM.

<div class="container">
    <div class="d-flex justify-content-start align-items-center m-4">
        <button type="button" class="btn btn-outline-primary me-2" id="select-destroy-destroy">destroy</button>
        <button type="button" class="btn btn-outline-primary ms-2" id="select-destroy-recreate">recreate</button>
    </div>
    <select multiple="multiple" id="select-destroy">
        <option value="Banana">Banana</option>
        <option value="Apple">Apple</option>
        <option value="Orange">Orange</option>
        <option value="Lemon" selected="selected">Lemon</option>
        <option value="Pepper">Pepper</option>
        <option value="Mushrooms">Mushrooms</option>
        <option value="Cabbages">Cabbages</option>
        <option value="Celery">Celery</option>
        <option value="Garlic">Garlic</option>
        <option value="Brocoli">Brocoli</option>
    </select>
</div>

let select = new betterNiceSelect.BetterNiceSelect("#select-destroy");

document.querySelector("#select-destroy-destroy").addEventListener("click", function () {
    select.destroy();
});

document.querySelector("#select-destroy-recreate").addEventListener("click", function () {
    select = new betterNiceSelect.BetterNiceSelect("#select-destroy");
});