Select selectedIndex Property - Deselect all options: - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Select

Description

Select selectedIndex Property - Deselect all options:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<select id="mySelect">
  <option>CSS</option>
  <option>Javascript</option>
  <option>Database</option>
  <option>SQL</option>
</select>/*from  www . j  a v a2s  .  c om*/

<p>Click the button to deselect options.</p>

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

<script>
function myFunction() {
    document.getElementById("mySelect").selectedIndex = "-1";
}
</script>

</body>
</html>

Related Tutorials