最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - remove specific items from dropdown list using jquery - Stack Overflow

programmeradmin0浏览0评论

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

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

Now, how can I remove the selected items from the dropdown list?

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

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

Now, how can I remove the selected items from the dropdown list?

Share Improve this question asked Apr 25, 2011 at 12:17 johnjohn 2,8536 gold badges24 silver badges14 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 12
$("#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

This could help you:- Remove Selected Option using jQuery

$("[Id$='ddlShowRun'] option:selected").remove();
发布评论

评论列表(0)

  1. 暂无评论