0

I've struggled to find the documentation for the add() method that's called to add Options 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);
NickW
  • 1,207
  • 1
  • 12
  • 52
  • 2
    a) you find the methods of inputs on MDN's [`HTMLInputElement`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) page, not on the [``](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input) one b) it's not an input but rather a [`select` element](https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement), which does have an [`add` method](https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/add) – Bergi May 08 '22 at 16:29

1 Answers1

0

SO Post

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);
Dean Van Greunen
  • 5,060
  • 2
  • 14
  • 28