1

I am new to jquery ui and I am trying to add a class to the selectmenu in jquery ui. I am trying this, but its not coming. Can somebody please help me in this

$('#dd1').change(function () {
            var input = $(this);;
            if (!input.val()) {
                input.selectmenu().addClass("test");
            }
            else{
                input.selectmenu().addClass("test1");
            }
        });

.test {border: 3px solid #FF0004;}
.test1 {border: 3px solid #28AF08;}

Is it the correct way to add class to select menu dynamically? Please guide me

user1049057
  • 459
  • 4
  • 15
  • 36

1 Answers1

1

Do you want to add a class to the original select element or to the generated elements?

You could add a class to button and menu by using: input.selectmenu( "widget" ).addClass( "test" );

Use .filter() to add a class to button or menu only.

fnagel
  • 654
  • 4
  • 11
  • It does not add a class this way. – Alexander Feb 09 '16 at 13:45
  • Which version you are using? There are old forks which does not have the widget method. This is the correct way for changing the official jQuery UI Selectmenu. – fnagel Feb 29 '16 at 15:32
  • Don't remember how i resolved this issue. Anyway, seems like what should work is input.selectmenu( "widget" ) or input.selectmenu( "widgetMenu" ) to access button or generated menu itself. Though, i have discovered i cannot assign something like width separately to those two elements. I've created workaround here, too. – Alexander Feb 29 '16 at 16:10