sam No1 sam No1 - 1 year ago 80
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.

Answer Source

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