Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

The 'add' method of input elements

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

const select = document.querySelector('.select-element');
const option = new Option(name, id);
select.add(option, undefined);

>Solution :

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);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading