Option text Property - Return the text of the selected option in a drop-down list: - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Option

Description

Option text Property - Return the text of the selected option in a drop-down list:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

Select your favorite fruit:
<select>
  <option id="a">Apple</option>
  <option id="orange">Orange</option>
  <option id="pineapple">Pineapple</option>
  <option id="banana">Banana</option>
</select>/*from w  ww  .  ja v  a 2 s . c o m*/

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

<script>
function myFunction() {
    var v = document.getElementById("a").text;
    console.log(v);
}
</script>

</body>
</html>

Related Tutorials