Last Updated: February 25, 2016
·
3.937K
· emi420

How to control the "select" element with JavaScript on iOS WebKit

If you are developing your custom UIs for mobile, you can hide the native select element and show your own hand-crafted dropdown control and selection list.

But I like the native selection list. I just want to replace and customize the dropdown control.

This is perfectly possible, you can control the open/close of the native element with focus/blur events:

var $openSelectionList = $("#openSelectionList");
var $selectionList = $("#selectionList");

$openSelectionList.on("touchend", function() {
      $selectionList[0].focus();
});

$selectionList.on("blur", function() {
    $openSelectionList.html(this.selectedIndex);
});

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside