Home » Jquery » javascript – Set default color in select menu not working

javascript – Set default color in select menu not working

Posted by: admin February 22, 2020 Leave a comment

Questions:

I developed simple select menu using select2 plugin and I want to highlight selected menu options in red. It’s working fine.

The problem

If I click the dropdown menu without selecting any items and click outside to close the menu, it will highlight default value in red. Please take a look at this fiddle.

https://jsfiddle.net/0Lorad6t/

I tried many ways. This is the recent one using jquery .blur() Tried to remove this class select2-container--above on blur it seems not working at all.

$(".select2-container").blur( function(){
   $( ".select2-container--default" ).removeClass( "select2-container--above" )
});

Any ideas to fix this?

How to&Answer: