How to set an event on click to DIV on the mobile version of the site?

$(document).on('click','.class', function(e) { ...
This kind of design is not perceived by the mobile browser only works if you do button
if to replace on
$(document).on('touchstart','.class', function(e) { ...

pressed in any scale, is not good,
how to be?

Not works only if you put the event on the DIV, in all other cases, works

$(document).on('click tap','button.fa',function(e) {
bk=true;
var spanText = $(this).val();
var x=spanText.split("_");
var id_tops = '<?php echo $id;?>';
e.preventDefault();
$.ajax({
 type: "POST",
 url: 'topchangepos.php',
 data: { 
 where: x[1],
 id: x[0],
 idtop: id_tops
},
 success: function(result) {
 if (x[1] === "up")
 {var res = +$("#"+x[0]+">p").text();
$("#"+x[0]+">p").text(res+1);}
 else if (x[1] === "down")
 {var res = +$("#"+x[0]+">p").text();
$("#"+x[0]+">p").text(res-1);}
}
});
});

var bk = false;
var currElClick = false;
 $(document).on('click tap','.visualp', function(e) {
 if (bk==true) {
bk=false;
return;
}
 var that = $(this);
 if (currElClick == $(that).find("button:first").val()) return false;
 currElClick = $(that).find("button:first").val();
spanText = $(this).find("button:first").val();
x=spanText.split("_");
var id_tops = '<?php echo $id;?>';
e.preventDefault();
$('.comments').remove();
$.ajax({
 type: "POST",
 url: 'showcommentstop.php',
 data: { 
 elementid: x[0],
 topid: id_tops
},
 success: function (list) {
 if (list == ") {
 } else {
$(that).append(list);
}
}
});
});
June 14th 19 at 20:46
1 answer
June 14th 19 at 20:48
$(document).on('click tap','.class', function(e) { ...

touch should also work fine
so, too, do not open, only in touchstart (if the div put all other elements of the work)

$(document).on('click tap','button.fa',function(e) {
bk=true;
var spanText = $(this).val();
var x=spanText.split("_");
var id_tops = '<?php echo $id;?>';
e.preventDefault();
$.ajax({
 type: "POST",
 url: 'topchangepos.php',
 data: { 
 where: x[1],
 id: x[0],
 idtop: id_tops
},
 success: function(result) {
 if (x[1] === "up")
 {var res = +$("#"+x[0]+">p").text();
$("#"+x[0]+">p").text(res+1);}
 else if (x[1] === "down")
 {var res = +$("#"+x[0]+">p").text();
$("#"+x[0]+">p").text(res-1);}
}
});
});

var bk = false;
var currElClick = false;
 $(document).on('click tap','.visualp', function(e) {
 if (bk==true) {
bk=false;
return;
}
 var that = $(this);
 if (currElClick == $(that).find("button:first").val()) return false;
 currElClick = $(that).find("button:first").val();
spanText = $(this).find("button:first").val();
x=spanText.split("_");
var id_tops = '<?php echo $id;?>';
e.preventDefault();
$('.comments').remove();
$.ajax({
 type: "POST",
 url: 'showcommentstop.php',
 data: { 
 elementid: x[0],
 topid: id_tops
},
 success: function (list) {
 if (list == ") {
 } else {
$(that).append(list);
}
}
});
});
- Elton.Zboncak commented on June 14th 19 at 20:51

Find more questions by tags JavaScript