Chosen, Multiselect & Limiting Selected Options on Mobile Devices

I use Chosen jQuery plugin to style and make multiple select (multiselect) dropdowns more user-friendly in my ProfilePress plugin.

One limitation of Chosen is, it is disabled on iPhone, iPod Touch, and Android mobile devices with the default select display shown instead.

Chosen has support for limiting the number of options that can be selectable but HTML select element do not. Since chosen is disabled on mobile devices, I needed to make native HTML select to support limiting selectable options.

I was able to achieve this with the JavaScript code below.

Code credit: http://stackoverflow.com/a/30475067/2648410