I got in trouble using the jQuery click event and safari on iPhone. On Windows, the event is fired when I open the select box and once again when I click on an option. On Safari at iPhone its only fired when I open the select box.
The JavaScript code T'm using look like this:
$('select').click(function() {
if ($(this).attr("data-click") == 1) {
var option = $(this).find('option:selected').val();
alert(option);
$(this).attr("data-click", 0);
} else {
$(this).attr("data-click", 1);
}
});
$('select').focusout(function() {
$(this).attr("data-click", 0);
});
And this is the html code:
<select>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
The point is, I cannot use $('select').change()
because I want to fire alert(option);
when the user opens the select box and even when he click on the same option that was selected before.
I created a JSFiddle for you to help you understand the problem. It should alert the item when you open the select box and click on an option.