How to add a specific class to select2 drop element?

后端 未结 4 2318
再見小時候
再見小時候 2021-02-18 18:23

I have select2 customized via css with its general classes and ids.

Now, I\'m trying to customize a specific class that will be provided to select2 and then apply in css

4条回答
  •  不思量自难忘°
    2021-02-18 18:36

    It's possible to make it in another way - via data-* of select2 - (if don't want to add select2.full.js). Use like it:

     var select2 = $(".element").select2({/* Select2 Opts */});
    

    Ok. Now push var select2 to console ( for understanding) like:

     console.log($(select2).data('select2'));
    

    You will see something like this:

    e {$element: init(1), id: "select2-....", options: e, listeners: Object, dataAdapter: d…}
     $container: init(1)
     $dropdown: init(1) <-- what you need!
     $element: init(1)
     $results: init(1)
     ....
    

    Ok, now just add specified class(-es) to select2's dropdown in the same way:

    select2.data('select2').$dropdown.addClass("...");
    

    Also, via $(select2).data('select2') you have access to others select2 elements (container, etc.).

提交回复
热议问题