简体   繁体   中英

jquery - div onclick - not working in iPhone

i tried different ways.
I need onclick for a div with jquery in my mobile site. On clicking on the div it will send an ajax call.

$(document).ready(function() {
... ...... 

$('body').on('click','.selectableCard', function() {

    $.ajax({
                url : URL}).done(
                function(data) {    .....    ....   });
        });
...
....
        });

This is working fine in desktop browsers and in android emulator. But not working in iPode4 .

Div

<div class="resultsMainContainer selectableCard  ">

style

.selectableCard {
    pointer-events: auto !important;
}
.resultsMainContainer {
    background-color: #FFFFFF;
    border: 1px solid #D6D6D6;
    box-shadow: 3px 3px 5px 1px #CCCCCC;
    display: inline-block;
    margin-bottom: 15px;
    padding-bottom: 10px;
    padding-left: 10px;
    padding-top: 10px;
    width: 98%;
}

I tried as:

$('.selectableCard').click(
        function(){....

But it's not working in desktop itself. !

Any idea would be appreciated :)

Here is an updated jsFiddle: http://jsfiddle.net/smilyface/y7DX5/1/

Will work fine in desktop , but not working in iPod

On iphone you must use touchevent for exemple:

$('.selectableCard').on('click touchstart',function(){
//your code
});

Got it working.

I just put the entire onclick function (onclick selectableCard) inside the ajax. So that it will run each time when the ajax loads. Thus it can get the class/div specified inside the jQuery.

$.ajax({
            url : URL
            }).done(
            function(data) {

                container.html(data); //innerHTML part
                $('.selectableCard').click(function(){..call div came through above innerHTML..});
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM