How can I create an option element using javascript and set it’s value [duplicate]

it has to do with DOM manipulation;

currencies.forEach((x)=>{
let selectElt = document.querySelector('.select-text');
let newElt = document.createElement('option');
let newText = document.createTextNode(x.name);
newElt.setAttribute('value', 'x.id');
newElt.appendChild(newText);
selectElt.appendChild(newElt);
})

Leave a Comment