c# - Remove item from DropDownList by value using javascript -


i have following dropdownlist.

@html.dropdownlist("attractionsavaiableattractions", model.avaiableattractions) 

i use script access dropdownlist located id td element. how can remove item dropdownlist by value not selected item?

$(document).ready(function () {             var table = document.getelementbyid('timetableattractions');             var rowlength = table.rows[0].length;             var row = table.rows[0];             (var y = 1; y < row.cells.length; y++) {                 var $td = $(row.cells[y]).closest("td");                 var itemtoremove = 'example';                 $td.find("[name^='attractionsavaiableattractions']").remove(itemtoremove);             }            }); 

please try,

var itemtoremove = 'example';  $("[name='attractionsavaiableattractions '] option[value='"+itemtoremove+"']").remove(); 

where attractionsavaiableattractions name of dropdown.

please find sample,

<!doctype html>  <html>  <head>      <script src="scripts/jquery-3.1.1.min.js"></script>      <meta charset="utf-8" />      <title></title>      <script type="text/javascript">                   function removeitem() {                  $("[name='programminglanguages'] option[value='2']").remove();              }      </script>  </head>  <body>      <select id="ddllist" name="programminglanguages">          <option value="www.codewithvijay.com">code</option>          <option value="2">c#</option>          <option value="3">java</option>          <option value="4">go</option>          <option value="5">c++</option>      </select>      <input type="button" onclick='removeitem()' value="click" />  </body>  </html>


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -