7

onClick event not working on tablet,ipad? it is perfectly working on Pc browser but not working for touch events , i tried .binding(),.on() and many thing but they are not giving 100% result.

How can I make it work on ipad , tablet??

<div id="id1" alt='div1' class="sliderImage" width="300" height="360" onclick="" style="visibility:hidden;background-image:url('img/img1.jpg'); border:solid; border-color: black;">You've styled the div to have a set width of 100px. At a reasonable font size, that's too much text to fit in 100px. Without doing anything, </div>
<div id="id2" alt='div2' class="sliderImage" width="300" height="360" onclick="" style="visibility:hidden;background-image:url('img/img2.jpg'); border:solid; border-color: black;">this is 2</div>
anam
  • 3,905
  • 16
  • 45
  • 85

3 Answers3

4

You need to use touchstart i get you a small example,

$('elementid').on('click touchstart', function() {
      console.log('1');
});

The touchstart event is fired when a touch point is placed on the touch surface.

Alex Raţiu
  • 107
  • 1
  • 12
  • 2020 and still working. but I used a function to identify the tablets and then I use just `touchstar` instead of `click tuchstart`. And keep using `click` for all other devices. Thanks! – Rafael Perozin Feb 12 '20 at 10:55
0

You can use tap, swipe, taphold etc events for the tablets,touch you can do this like

$('htmlelement').bind('click', ClickFunction ).bind('tap', ClickFunction );

Here are the list of jquery mobile events events

Also try to use the jquerymobile

M Khalid Junaid
  • 63,861
  • 10
  • 90
  • 118
  • ,Uncaught TypeError: Object .sliderImage has no method 'apply' i get these error if i use .bind() – anam Jun 18 '13 at 06:26
0

You must have to bind the 'click' or 'tap' event for associated HTML control. You can bind like this

$('elementid').bind('click',function() {   alert('Click event triggered'); });

OR

$('elementid').bind('tap',function() {  alert('Tap event triggered'); });
pobrelkey
  • 5,853
  • 20
  • 29
Hitesh
  • 45
  • 1
  • 4