Search code examples
javascriptjqueryjquery-select2jquery-select2-4

How to see the set options to a select2 instance?


I want to get the options set to a select2 instance, in specific if the allowClear option is set to true or false.
Navigating through the object I found the allowClear option in

jQuery... -> select2 -> options -> options,

but I don't know how to access to it via code.

enter image description here


Solution

  • This is how to list all of the options set to a select2 instance

    $(selector).data('select2').options.options
    

    I needed the allowClear option so the answer to my question would be this

    $element.data('select2').options.options.allowClear