Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
53
rated 0 times [  58] [ 5]  / answers: 1 / hits: 16788  / 10 Years ago, sun, november 16, 2014, 12:00:00

First of all, I know this has been answered a lot of times, but all the things I try to do, they're not working. So here's my problem:



I have a non-displayed div that I want to show when the users clicks a div, so I have this javascript code:



$(document).ready(function() {
$(.hamburger-menu).on(click, function(){
var display = $(.menu-mobile).css(display);
if (display == none) {
$(.menu-mobile).css(display, block);
} else {
$(.menu-mobile).css(display, none);
}
});
});


This works perfectly on my desktop but doesn't work in my mobile.

What I found in the other answers was to change the .on(click) value to .on(click touchstart) or .on(tap), but they both don't work.



So what's the problem? I have another animation that doesn't require any click event and it works perfectly and smoothly on my mobile. Could anyone help me?



Thanks.


More From » jquery

 Answers
15

there are some issues with jquery and detecting touches. i find it best to set event listeners with javascript for this sort of thing. I've had luck with something like this:



this.addEventListener('touchend', function(e){happens(e)}, false);


touchend is a good mouseup equivalent for mobile. touchstart should work for mousedown like you were trying.


[#68790] Thursday, November 13, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tomas

Total Points: 165
Total Questions: 111
Total Answers: 103

Location: Maldives
Member since Tue, Dec 21, 2021
3 Years ago
tomas questions
Thu, Jan 27, 22, 00:00, 2 Years ago
Mon, May 10, 21, 00:00, 3 Years ago
Tue, Jan 5, 21, 00:00, 3 Years ago
;