0

This is a really strange case.

If I click an element, the class of div disappears immediately both PC and MAC. Using removeClass it was fine that I want.

However mobile devices(iPhone and Android) are something wrong. When I try to click an element the class does not remove on the screen. But the console print out that the class go away. So I click any area of blank this element show as it normal.

I don't know why this issue happen to mobile device? What can I do to make the screen show immediate reaction?

$(".div").on('click touch', function(){
    var idx = $(this).index(".div");
    if($(this).hasClass("yellow")){
          $(this).removeClass("yellow");
    }
}
Richard
  • 351
  • 4
  • 17

2 Answers2

1

Can u try touchstart instead of touch

$(".div").on('click touchstart', function(){
   var idx = $(this).index(".div");
   if($(this).hasClass("yellow")){
      $(this).removeClass("yellow");
   }
}

if Its a dynamic element, u must trigger for body

$("body").on('click touchstart', '.div', function(){
   .....
}
Ryan Nghiem
  • 2,417
  • 2
  • 18
  • 28
1

use touchstart

$(document).on('click touchstart', function () {

ref document .click function for touch device

Deepak A
  • 1,624
  • 1
  • 7
  • 16