Option label Property - Alert the label value of the selected option in a drop-down list: - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Option

Description

Option label Property - Alert the label value of the selected option in a drop-down list:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

Select your favorite car:
<br>
<select id="mySelect" size="4">
    <option label="c">cc</option>
    <option id="myOption" label="d">dd</option>

</select>//from  w  w  w  .j  a  v a  2  s  .c o m

<button type="button" onclick="myFunction()">Test</button>

<script>
function myFunction() {
    var x = document.getElementById("mySelect").selectedIndex;
    console.log(document.getElementsByTagName("option")[x].label);
}
</script>

</body>
</html>

Related Tutorials