javascript - Using jQuery to delete an option value from a select box using the delete key -
using jquery, how can 1 remove option value select box using on keypress of delete key? here html part need use process:
<select id="cars"> <option value="volvo">volvo</option> <option value="saab">saab</option> <option value="mercedes">mercedes</option> <option value="audi">audi</option> </select>
use this:
$("#select").keydown(function(event) { if(event.which != 46) { return } var sel = $(this); var val = sel.val(); if(val != "") { sel.find("option[value="+val+"]").remove(); } });
Comments
Post a Comment