[Solved] JavaScript – how to remove `options` by its `value`


<select class="fruits" >
  <option value="1" >Oranges</option> 
  <option value="2" >Bananas</option> 
  <option value="3" >Apples</option> 
</select>

<script type="text/javascript">

var valueToRemove = 1;
	
var select = document.getElementsByClassName('fruits');

for(var i = 0; i < select[0].length; i++) {
	if(select[0][i].value == valueToRemove) {
		select[0][i].remove();
	}
}



</script>

Edit:

<select class="fruits" >
  <option value="1">Oranges</option> 
  <option value="2">Bananas</option> 
  <option value="3">Apples</option> 
</select>

<br>

<label>Input value to delete</label><input type="text" id='delete_value'>
<button onclick='remove(document.getElementById("delete_value").value)'>Delete</button>

<script type="text/javascript">




function remove(item) {
	var valueToRemove = item;
	
	var select = document.getElementsByClassName('fruits');


	for(var i = 0; i < select[0].length; i++) {
		if(select[0][i].value == valueToRemove) {
			select[0][i].remove();
		}
	}

}



</script>

3

solved JavaScript – how to remove `options` by its `value`