There is a select of the form:

<select multiple id="my-select"> <option value="1">first</option> <option value="2">second</option> <option value="3">third</option> </select> 

How to programmatically set the focus to this select?

I am writing on ionic 1.3.
Check any answers.

  • Try $('#my-select').focus() - Stepan Kasyanenko

2 answers 2

Although the post is correct, I would recommend using “click” instead of “mousedown”. All the same, you write on the IONIC Framework, and this is a mobile device, and just click, it simulates the Touch Event with you. And what's more important, if I'm not mistaken, "mousedown" when you put together the iOS platform will not work, while on Android everything will be ok.

  • Thanks for your reply. Yes, you're right, ios does not work. Soon it will not be possible to check - will “click” work everywhere? - Max

Wrote this method to select an element:

 function clickByElement(selector) { $timeout(function() { var element = $(selector)[0]; var event = document.createEvent('MouseEvents'); event.initMouseEvent('mousedown', true, true, window); element.dispatchEvent(event); }); } 

After adding $ timeout, it worked.