JSFiddle - React, Tailwind, and code Playground

by Julien Etienne

HTML

<h1>Emulate Click Event on Select Option</h1>

    <select id="mySelect">
        <option value="option1">Option 1</option>
        <option value="option2">Option 2</option>
        <option value="option3">Option 3</option>
    </select>

  <button onclick="selectOption3()">Select Option 3</button>

CSS

/* Style for the select element */
        select {
            width: 200px;
            padding: 10px;
        }

JavaScript

function selectOption3() {
            // Get a reference to the select element
            var select = document.getElementById('mySelect');

            // Set the selectedIndex to 2 to select the third option (0-based index)
            select.selectedIndex = 2;
        }