How to change the css of color of select2 tags?

后端 未结 8 1883
萌比男神i
萌比男神i 2020-12-31 06:47

I just started using project for showing multiple tags from a select box and it works great, thanks for the library.

I just need to modify the color or css of the ta

8条回答
  •  鱼传尺愫
    2020-12-31 07:35

    For formatting the tags you can use the function formatSelectionCssClass.

    $("#mySelect").select2({
        formatSelectionCssClass: function (data, container) { return "myCssClass"; },
    });
    

    Or you could add a css class based on the option id:

    $("#mySelect").select2({
        formatSelectionCssClass: function (data, container) { return data.id; },
    });
    

    Remember that you will need to override both filter and background_color in your css class

提交回复
热议问题