0

I use the jQuery combobox plugin:

https://jqueryui.com/autocomplete/#combobox

My JS:

 $(function() {
    $( "#combobox" ).combobox();
    $( "#toggle" ).click(function() {
      $( "#combobox" ).toggle();
    });
  });

My goal is to add a custom class to the autocomplete div in order to individually style the autocomplete dropdown. I already tried the following, but this is not working:

$( "#combobox" ).combobox().autocomplete("widget").addClass('my-custom-autocomplete-class');
3
  • If you inspect the dropdown you can see that it already has a class named ui-autocomplete
    – Reyno
    Mar 31, 2016 at 12:17
  • The autocomplete widget is bound against an input appended an inserted span. You can get it using $("#combobox").next("span").find("input"). Of course, you could also go the none-insane-way and use the appropriate selector $(".custom-combobox-input")
    – blgt
    Mar 31, 2016 at 12:47
  • @theblackgigant I know! My goal is to give it an extra custom class.
    – Max
    Mar 31, 2016 at 12:50

1 Answer 1

0

Try This, As per selected value class add to combobox write css for each option mention in drop down

$(function($) {
$( 'select[id=combobox]' ).on("change",function() {
  var dynaminClass = $(this).val();
  console.log(dynaminClass);  
  $(this).attr('class', dynaminClass);

})

})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.