How to add class to select2 element in v4.0

后端 未结 5 1611
故里飘歌
故里飘歌 2021-02-12 04:04

This is very similar to this question on how to add class to select2 element, however the answers there appear to target earlier versions of the framework which has undergone so

5条回答
  •  日久生厌
    2021-02-12 05:05

    Found a way to add a class. had the same problem couldnt find a way and made it myself, so here it is:

    $('.select2').on('click',function(){
      var matchBlock = $(this).prev();
      if(matchBlock.hasClass('select-control-left')){
        $('.select2-dropdown').addClass('blue-select');
      }
      else{
         $('.select2-dropdown').addClass('orange-select');
      }
    });
    

提交回复
热议问题