sam No1 sam No1 - 5 months ago 5x
Javascript Question

How to focus on an element using jQuery?

I have following html

<span>Click me</span>
<option value="1" selected="selected">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>


$('span').on('click', function () {

What I want to do is when I click on span tag the select menu needed to be focused and dropped down without changing the structure. I spent hours to find a solution for this but I couldn't.


You have used input as selector in fiddle. it should be select instead:

$('span').on('click', function () {

Working Demo

Update: For opening dropdown-

var dropdown = $('select')[0];
event = document.createEvent('MouseEvents');
event.initMouseEvent('mousedown', true, true, window);

Working Demo