⊗jsPmSlOS 413 of 504 menu

Selecting a list item in JavaScript

In previous lessons, we accessed the select tag to get or change the selected list item. It's not really necessary. After all, you can directly set the property selected of some option tag to true.

For example, let's make the list item with number two selected:

let select = document.querySelector('#select'); let option = select[2]; option.selected = true;

Given a dropdown list and a button. By clicking on the button, make selected the last item in the list.

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