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

give attributes to <option> from javascript

So, I have this piece of JS:

for(var index in response.rates) {
    select.options[select.options.length] = new Option([index], index);
}

It generates the and tags populated with an array.

How can I give attributes to from there? Like onselect and and other things.

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

Thanks

>Solution :

Assign the option to a variable then you can give it attributes.

for(var index in response.rates) {
    let option = new Option(index, index);
    option.addEventListener("select", ...);
    select.options[select.options.length] = option;
}
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