How to remove all options from dropdown and add new option in JQuery

How to remove all options from dropdown and add new option in JQuery

<html>
	<head>
		<title>Codelizar JQuery Blog</title>
		<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
		<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
		<script src='https://code.jquery.com/jquery-3.4.1.js'></script>
		<script type='text/javascript'>
			$(document).ready(function(){
				$('#select_box')
				    .empty()
				    .append('<option selected="selected" value="4">Android Studio</option>')
				;
			});
		</script>
	</head>
	<body>
		<select id="select_box" class="form-control">
			<option value="0">Select Software</option>
			<option value="1">Eclipse</option>
			<option value="2">VLC Media Player</option>
			<option value="3">WinZip</option>
		</select>
	</body>
</html>

 

Leave a Reply

Your email address will not be published. Required fields are marked *