How to clear a selected value in Selectize.js dropdown?

I finally found the answer here Selectize.js Demos

What works for me is:

 var $select = $('#optionNetFlow').selectize();
 var control = $select[0].selectize;
 control.clear();

what I was missing var $select = $('#optionNetFlow').selectize(); before applying the solution provided in above question's answer.

Now I am to get all the functions in console like :

enter image description here


Try this,

$("#optionNetFlow")[0].selectize.clear();

Try this out:- http://jsfiddle.net/adiioo7/2gnq1ruv/204/

JS:-

jQuery(function ($) {
    var $select = $('#input-tags').selectize({
        persist: false,
        create: true
    });

    $("#btnClear").on("click", function () {
        var selectize = $select[0].selectize;
        selectize.clear();

    });
});

All other answers either clear a single selectize or need a specific reference to the selectize in the moment of it's creation.

The solution below, on the other hand, works for any number of selectize elements you have inside any form; you just need to specify the desired form:

$('form').find('.selectized').each(function(index, element) { element.selectize && element.selectize.clear() })

The rationale is that Selectize keeps the original element in the DOM (hiding it), adds a reference to the selectize on the .selectize property of the DOM element and adds a CSS class selectized to it.

So the solution finds all the elements that have the CSS class selectized, loops through them and calls element.selectize.clear().