How to remove options from select using jQuery

We  can sort an array using this method:

  1. This is the select (HTML):
    <select name="selectBox" id="selectBox">
        <option value="option1">option1</option>
        <option value="option2">option2</option>
        <option value="option3">option3</option>
        <option value="option4">option4</option>	
    </select>
  2. How to remove the items. Just do:
    //Deleting all the items with value equals to 'X':
    $("#selectBox option[value='X']").each(function() {
        $(this).remove();
    });
    //Or:
    $("#selectBox option[value='X']").remove();

Reference link: http://stackoverflow.com/questions/375508/removing-an-item-from-a-select-box

Advertisements