Search code examples
jqueryjquery-ui-multiselect

ui multiselect add class to li when selected?


is there any option to add class to the selected li i.e the options selected, if so how cani add and get the values?

close: function(event, ui){
var selectedValues = $('#VendorNum').val();
 $('.ui-multiselect-checkboxes li').each(function(){
    if($(this).is(":selected")){
    alert(selectedValues);   
    }
 });  

}

The alert is not working here


Solution

  • ":selected" selector may be used only on "option" elements, not "li".

    Try this code:

    click: function(event, ui){
     $('.ui-multiselect-checkboxes li').removeClass("highlight");
     $(this).addClass("highlight");  
    },
    close: function(event, ui){
     alert($('.ui-multiselect-checkboxes').multiselect('getChecked').join(", "));
    }