Answers for "html select element remove all options"

3

remove all options from select jquery

$('#mySelect')
    .empty()
Posted by: Guest on March-18-2020
0

clear select dropdown js

var courses = document.getElementById("special_selection");

    // clear select
    var length = courses.options.length;
    for (i = length - 1; i >= 0; i--) {
      courses.options[i] = null;
    }
    for (var i = 0; i < data.length; i++) {
      var option = document.createElement("OPTION"),
          txt = document.createTextNode(data[i].coursetitle);
      option.appendChild(txt);
      option.setAttribute("value", data[i].KF);
      courses.insertBefore(option, courses.lastChild);

    }
Posted by: Guest on June-25-2021

Code answers related to "html select element remove all options"

Code answers related to "Javascript"

Browse Popular Code Answers by Language