How to clear all selected items in a SELECT input using jQuery?

前端 未结 10 1787
北海茫月
北海茫月 2020-12-28 13:55

I am think this should be fairly easy, but struggling a bit ... I have a SELECT input element that allows the user to select multiple items. I would like to pro

相关标签:
10条回答
  • 2020-12-28 14:13

    This solution worked for me...

    $('#my-Select').val('').trigger('change');
    

    This works on almost any input type.

    0 讨论(0)
  • 2020-12-28 14:13

    Better than this, you can use:

    $("#selectID").empty();
    

    That works on almost anything in the DOM.

    0 讨论(0)
  • 2020-12-28 14:18

    Try that:

    $("#selectID").empty();
    

    Worked for me!

    0 讨论(0)
  • 2020-12-28 14:20

    Only this worked for me:-

    $("#selectid").find('option').attr("selected",false) ;
    
    0 讨论(0)
  • 2020-12-28 14:23

    This worked to clear all selected options for me..

    $("#selectListName").prop('selectedIndex', -1)
    

    The select list looked like

    <select multiple='multiple' id='selectListName'> 
      <option>1</option> 
      <option>2</option> 
      <option>3</option> 
      <option>4</option>
    </select>
    
    0 讨论(0)
  • 2020-12-28 14:24

    Try: // Just put # before select to fix this. Works perfect. $("#select option:selected").each(function () { $(this).remove(); //or whatever else });

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