Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
104
rated 0 times [  106] [ 2]  / answers: 1 / hits: 20741  / 8 Years ago, fri, march 11, 2016, 12:00:00

Can anyone please explain to me why this is working in the browser but not on mobile devices like Apple's iPhone. On iPhone, I never get the hello from the alert. Why?



<div class=close>
Click here
</div>


JS:



$(document).on('click', '.close', function() {
alert('hello');
});


Example here: https://jsfiddle.net/27ezjrqr/5/


More From » jquery

 Answers
18

By default, divs are not a clickable elements. But adding cursor: pointer; makes iOS treat it as clickable.



So all you need to do is add



.close {
cursor: pointer;
}


to your CSS and then it will work.



Proof here: https://jsfiddle.net/27ezjrqr/6/





$(document).on('click', '.close', function() {
alert('hello');
});

.close {
cursor: pointer;
}

<script src=https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js></script>
<div class=close>
Click here
</div>




[#62974] Wednesday, March 9, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alenaautump

Total Points: 87
Total Questions: 109
Total Answers: 109

Location: Libya
Member since Mon, Dec 7, 2020
4 Years ago
alenaautump questions
Fri, Nov 12, 21, 00:00, 3 Years ago
Wed, Feb 17, 21, 00:00, 3 Years ago
Mon, Jan 25, 21, 00:00, 3 Years ago
;