Skip to content Skip to sidebar Skip to footer

Get Options Value Using Tag Name In Javascript

I have this HTML I want to

Solution 1:

document.getElementsByTagName() returns an HTMLCollection(which is a kind of an array), so it does have the options properties. You can access the items in the list using indexing.

var parent = document.getElementsByTagName('select')[0];
var tempUnit = parent.options[parent.selectedIndex].value;

document.querySelector('#result').innerHTML = tempUnit
<selectid="tempSelect" ><optionvalue="F">Fahrenheit</option><optionvalue="C"selected>Celsius</option></select><divid="result"></div>

Post a Comment for "Get Options Value Using Tag Name In Javascript"