How to filter out option tags from the original select with Select2?

javascript, jquery, jquery-select2

Solution

It appears the OP found the answer at https://github.com/select2/select2/issues/1048.

The answer is to supply a `matcher` function.

$("#select").select2({
    matcher: function(term, text, option) {
        return option.hasClass('car');
    }
});

jsfiddle

Problem

Seems like a pretty simple idea, but I can't figure out how to filter out option tags of the original select from the select2 dropdown. Basically, this: ``` <select id="select"> <option class="car">Car 1</option> <option class="plane">Plane 1</option> </select> $("#select").select2(); ``` ... should create a fake select with only the option tags with the class `car`.

Original source