remove specific items from dropdown list using jquery

前端 未结 3 874
盖世英雄少女心
盖世英雄少女心 2021-01-23 00:11

I have a multi select dropdown list. I can get the array of selected values using:

selectedItems = $(\"#myList\").val(); // works.

Now, how can

相关标签:
3条回答
  • 2021-01-23 00:47
    $("[Id$='ddlShowRun'] option:selected").remove();
    
    0 讨论(0)
  • 2021-01-23 00:50
    $("#myList option:selected").remove();
    

    will work.


    Edit: I misunderstood the comment, but I will leave it as an example for removing certain elements in general.
    If you want to remove the elements based on the value in the array, you have to loop over the array:

    var $list = $("#myList"),
        toRemove = $();
    
    for(var i = selectedItems.length; i--;) {
       toRemove = toRemove.add($list.find('option[value="' + selectedItems[i] + '"]'));
    }
    toRemove.remove();
    

    DEMO

    0 讨论(0)
  • 2021-01-23 00:55

    This could help you:- Remove Selected Option using jQuery

    0 讨论(0)
提交回复
热议问题