Ad Code

How to remove all entry from dropdown except first one

First, do not duplicate id values (this causes JavaScript to get confused), but you can do so with classes. Secondly, you can just use:


$("option:not(:first)").remove();
Also note, you are not closing the tag correctly:


$(function () {
  $("#models").find("option:not(:first)").remove();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<select id="models">
  <option value="">--Select--</option>
  <option value="0">R8</option>
  <option value="1">Quattro</option>
  <option value="2">A6 hatchback</option>
</select>

Post a Comment

0 Comments