How to get the HTML select option tag text in JavaScript

1 Answer

0 votes
<select id="select_id">
    <option hidden>Select Option</option>
    <option value="javascript">javascript text</option>
    <option value="php">php text</option>
    <option value="css">css text</option>
    <option value="html">html text</option>
</select>
const so = document.getElementById('select_id');

so.addEventListener('change', ()=>{
    console.log(so.options[so.selectedIndex].text);
});



    
    
/*
run:
    
"javascript text"
"php text"
    
*/

 



answered Jun 13, 2021 by avibootz
...