Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onclick event is not working on ipad and tablet

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>
like image 713
anam Avatar asked Jun 18 '13 05:06

anam


People also ask

Does click event work on mobile?

Rise of MobileOn a phone, mouse click doesn't exist. Instead, there are only touch events. This isn't entirely true, because some devices on some browsers for some elements will simulate a mouse click when a touch is made.

What is on click event?

The onclick event generally occurs when the user clicks on an element. It allows the programmer to execute a JavaScript's function when an element gets clicked. This event can be used for validating a form, warning messages and many more. Using JavaScript, this event can be dynamically added to any element.


1 Answers

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.

like image 181
Alex Raţiu Avatar answered Oct 27 '22 16:10

Alex Raţiu