How to hide or remove options from jQuery Chosen select dropdown

前端 未结 5 1253
野性不改
野性不改 2021-01-11 19:56

I would like to hide certain elements from a dropdown that is created using the Chosen plugin.

I have tried removing it:

$( \'option:contains(\"Swatc         


        
5条回答
  •  佛祖请我去吃肉
    2021-01-11 20:37

    In the original select you need to hide the option. For example:

    $('select.chosen-select options:contains("Swatch 1")');
    

    Then update the chosen options with:

    $('select.chosen-select').trigger("chosen:updated");
    

    If you have more than one chosen drop down on the page then it probably would be better to use a more specific id or class on that element in the place of $('select.chosen-select'). So your code would become:

    $('#swatch_select options:contains("Swatch 1")');
    $('#swatch_select').trigger("chosen:updated");
    

提交回复
热议问题