⊗jsPmSlOp 412 of 504 menu

Working with dropdown list items in JavaScript

Let us have a reference to the option tag in a variable. For example, obtained as follows:

let select = document.querySelector('#select'); let option = select[0];

In this case, the text property will store the text of the option, the value property will store the value of the attribute of the same name, and the selected property will store the value of true or false depending on whether the list item is selected or not:

console.log(option.text); console.log(option.value); console.log(option.selected);

Go through the list items in a loop and add an exclamation mark to the end of the text for the selected item, and a question mark for unselected items.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline