0

I am using jQuery click event for toggling my navigation bar. The code I am using is something like this:

$('.nav-button').on('click', function () {

    $('.navigation, .nav-button').toggleClass('show-nav');

});

Where .nav-button is a div. Everything is fine in Android version of Chrome, but Firefox Android is not doing anything on touching the <div class="nav-button"></div>

Is there any solution, or alternative for jQuery click event for touch devices?

Rosa
  • 642
  • 6
  • 20
Nafees Anwar
  • 6,324
  • 2
  • 23
  • 42

3 Answers3

2

Use this instead:

$('.nav-button').on('click touchstart', function () {

    $('.navigation, .nav-button').toggleClass('show-nav');

});
Nafees Anwar
  • 6,324
  • 2
  • 23
  • 42
0

Which jQuery are you using? I recommend using the jQuery Mobile library. Its almost the same as the jQuery . They have events that are specific to touch devices in jQuery Mobile.

eg

$("p").on("tap",function(){
  $(this).hide();
});

$("p").on("taphold",function(){
  $(this).hide();
});

$("p").on("swipeleft",function(){
  alert("You swiped left!");
});
0

I found another thread on this topic on stackoverflow: jQuery click event not working in mobile browsers

As my previous speaker mentioned you could try it with jQuery Mobile. There is something similiar to the click event handler which is called vclick in jQuery Mobile:

Here a small example how it looks like:

$(document).ready(function(){
    $('.nav-button').vclick(function() {
        $('.navigation, .nav-button').toggleClass('show-nav');
    });
});
Community
  • 1
  • 1
Edgar Klepek
  • 11
  • 1
  • 6