How to Remove duplicate dropdown option elements with same value

后端 未结 8 1085
孤城傲影
孤城傲影 2020-12-03 18:48

How can I remove duplicate values -> drop down option elements?
I have the following HTML:


8条回答
  •  被撕碎了的回忆
    2020-12-03 19:23

    Using .siblings() (to target sibling option elements), and Attribute Equals Selector [attr=""]

    $(".select option").val(function(idx, val) {
      $(this).siblings('[value="'+ val +'"]').remove();
    });
    
    
    

    (works also for multiple .select on the same page)
    I added a class .select to the

    提交评论

提交回复
热议问题