3

Possible Duplicate:
How to bind 'touchstart' and 'click' events but not respond to both?

I have a strange issue where an html button doesn't work on tablets only. Works on all browsers and even mobile devices but not on actual tablets.

I've used buttons before without problems and can't see what the difference is. My code:

<button type="button" class="addwebcam">Add Webcam</button>
jQuery('.addwebcam').click(function(e) {
    jQuery('#cameraformwebcam').show(); //opens up a new form
    jQuery('.addwebcam').hide(); //now hide the button
});

I also have other buttons doing different things and they are all the same. Pressing the button on the tablet does nothing but highlight it. How can I debug this? I've tried user agents but they don't help me with debugging because the issue is with tapping the button on that actual device.

Community
  • 1
  • 1
Tom
  • 2,604
  • 11
  • 57
  • 96
  • This is worth a read: http://stackoverflow.com/questions/8939136/javascript-events-are-not-working-in-tablet-pc – 3dgoo Dec 19 '12 at 04:08

3 Answers3

1

Make sure jQuery is correctly loaded ans JS is enabled.


Also as mentioned in the comments by @3dgoo

Add the tap event along with the click

jQuery('.addwebcam').bind('click tap', function(e) {
    jQuery('#cameraformwebcam').show(); //opens up a new form
    jQuery('.addwebcam').hide(); //now hide the button
});
Community
  • 1
  • 1
Gabriele Petrioli
  • 191,379
  • 34
  • 261
  • 317
  • That doesn't seem to work for me. Same behavior. jQuery and JS is enabled – Tom Dec 19 '12 at 04:31
  • 1
    Good solution for jquery mobile but I didn't want to do this. I used `touchstart` and `touchend` solution. – Tom Dec 20 '12 at 03:16
  • @Tom, thanks for getting back and letting us know what worked.. might come in handy.. – Gabriele Petrioli Dec 20 '12 at 10:16
  • 1
    I should have added the link. It comes from Rafael Fragoso (not the accepted answer) and can be found [here](http://stackoverflow.com/questions/7018919/how-to-bind-touchstart-and-click-events-but-not-respond-to-both) – Tom Dec 21 '12 at 16:03
0

Try this

Replace <button type="button" class="addwebcam">Add Webcam</button>, with

<input type="submit" class="addwebcam" value="Add Webcam"/>

Hope this will works

Asish AP
  • 4,421
  • 2
  • 28
  • 50
0

You need to bind to the tap event.

Kyle Nunery
  • 2,048
  • 19
  • 23