I've struggled to find the documentation for the add()
method that's called to add Option
s to input elements.
I've looked on MDN here, but can't see it there or in the parent interfaces either. I was just wondering where I could find it, or what the 2nd parameter was for.
Eg:
const select = document.querySelector('.select-element');
const option = new Option(name, id);
select.add(option, undefined);
CodePudding user response:
Documentation for the add
function
// get selector element
var daySelect = document.getElementById("myDaySelect");
// create new option
var myOption = document.createElement("option");
myOption.text = "test";
myOption.value = "value";
// add new option
daySelect.add(myOption);