5
<select>
   <option>Jan</option>
   <option>Feb</option>
   <option>Mar</option>
</select>

The value which has been selected should not be appeared in the drop down. For instance, if i select "feb", Feb shouldn't appear in dropdown.

jsfiddle link: http://jsfiddle.net/jucLsmjx/

Roko C. Buljan
  • 196,159
  • 39
  • 305
  • 313
Shawn
  • 51
  • 1
  • 2

3 Answers3

2
$('#mySelect').on("change", function(){
    $('option:selected', this).hide().siblings().show();
});

Additionally if you want to trigger the Option Hide right from the start, add .trigger('change');:

$('#mySelect').on("change", function(){
    $('option:selected', this).hide().siblings().show(); 
}).trigger('change');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="mySelect">
  <option>a</option>
  <option>b</option>
  <option>c</option>
</select>
Roko C. Buljan
  • 196,159
  • 39
  • 305
  • 313
0

Your selector option[value=' + optionval + ']') is wrong. You are trying to select the option by its value but value='XXX' attribute is missing, so try this:

http://jsfiddle.net/jucLsmjx/8/

$('#mySelect').change(function(){
    var optionval = $('#mySelect').val();
    $('#mySelect  option:contains("'+optionval+'")').hide().siblings().show();;

});
angelcool.net
  • 2,505
  • 1
  • 24
  • 26
0

Just clone it(select element) and store it inside a variable

var $original = $("#mySelect").clone(true); // The argument "true" copies any event handlers.

Then go on and remove the selected <option> from the <select>

$("#mySelect").change( function(e){
  e.preventDefault();
  var val = $(this).val();
  $("#mySelect option[value='"+val+"']").remove();
});

The cloning part was for the case where you needed the original DOM element, then you can always append it to the DOM.

Mohd Abdul Mujib
  • 13,071
  • 8
  • 64
  • 88
  • Hiding options is **NOT** cross-browser compatible :-http://stackoverflow.com/questions/1271503/hide-options-in-a-select-list-using-jquery#comment6196140_1271528 – Mohd Abdul Mujib Aug 04 '15 at 03:19