JQuery.focus () not working on android
I am developing a mobile site on Android where I have a select list as a menu.
the select list is located outside of the viewport and I want to toggle the options popup in the browser by clicking on the div.
I've already tried millions of ways to open a view to select a value, but none have been successful ... After a little research, I read this StackOverflow question that the .focus () function is disabled on an android device ...
I know this code works on IOS:
$(document).ready(function(){
$("#navigation").click(function(){
$("#mobileMenu").focus();
});
});
with the following html:
<select id="mobileMenu">
<option value="link1" onclick='openMobileMenuLink' >link one</option>
<option value="link2" onclick='openMobileMenuLink' >link two</option>
<option value="link3" onclick='openMobileMenuLink' >link three</option>
</select>
Is there a way to open the perspective of options on an android device (I'm testing in chrome) without breaking the code (which works fine on IOS).
source to share
Finally I found a solution:
when the div is clicked, the click event is fired with js.
<div onclick="generateSelectDropDown()">
The above div calls the following function:
window.generateSelectDropDown = function () {
var dropdown = document.getElementById('mobileMenu');
showDropdown(dropdown);
};
showDropdown = function (element) {
var event;
event = document.createEvent('MouseEvents');
event.initMouseEvent('mousedown', true, true, window);
element.dispatchEvent(event);
};
source to share