mikemaccana mikemaccana - 22 days ago 12
Javascript Question

How can I focus on a selectize select box?

Focusing on a select box (that has selectize enabled) does not focus on the selectized input box:

$('.someclass select').focus();


Focusing on selectize's own inout box doesn't seem to work either:

$('.someclass input').focus();


The Selectize docs mentions
focus
but that doesn't seem to work either. See this jsfiddle:

var selectized = $('#selectize').selectize();
selectized.focus();


I would expect the carat
|
to be ready and typing to immediately go into the box.

How can I focus on a selectize select box from JavaScript, so a user can type into it?

Answer

One way which appears to work is to call click() instead of focus():

$('.someclass input').click();