35

Ok, what im trying to do is slide a div down when the user clicks a list item.

Problem is I am using Selectric https://github.com/lcdsantos/jQuery-Selectric which converts a Select box to an unordered list. So when the user clicks a which the source outputs as a list item I want a div to slide down.

On mobile safari (iOS7) the selectbox UI is the same as the standard selectbox UI.

What is the best practice when it comes to onClick for mobile devices?

Basic jquery:

$(window).load(function() {
        $('.List li').click(function() {
            $('.Div').slideDown('500');
        });
    });

You can see a working example HERE (Advanced search on the side bar)

Thanks.

Dale
  • 925
  • 2
  • 9
  • 21

3 Answers3

92

better to use touchstart event with .on() jQuery method:

$(window).load(function() { // better to use $(document).ready(function(){
    $('.List li').on('click touchstart', function() {
        $('.Div').slideDown('500');
    });
});

And i don't understand why you are using $(window).load() method because it waits for everything on a page to be loaded, this tend to be slow, while you can use $(document).ready() method which does not wait for each element on the page to be loaded first.

Jai
  • 72,925
  • 12
  • 73
  • 99
8

you can use instead of click :

$('#whatever').on('touchstart click', function(){ /* do something... */ });
Ram Patidar
  • 656
  • 1
  • 6
  • 15
  • 8
    Just a note: This code will trigger twice for a device that has both events fired or in the chrome dev tools, while mobile emulatin the view – wick3d Nov 10 '16 at 09:48
0

I also don't know why, but these 2 buttons cannot be clicked on the ipad safari.

<div class="col-md-6 text-center">
  <h3>Title</h3>
  <div class="col-xs-12">
    <div class="panel panel-default">
      <div class="pd20 bg">
        <h4 class="title">House</h4>
      </div>
      <div class="panel-footer text-center">
        <button type="button" class="btn btn-warning btn-sm" ng-click="vm.clear()">
          <i class="fa fa-edit" aria-hidden="true"></i> Clear</button>
        <button type="button" class="btn btn-warning btn-sm" ng-click="vm.submit()">
          <i class="fa fa-edit" aria-hidden="true"></i> Submit</button>
      </div>
    </div>
  </div>
</div>

But if I fix it like this, it can be clicked

<div class="col-md-6 text-center">
  <h3>Title</h3>
  <div class="row">
    <div class="col-xs-12">
      <div class="panel panel-default">
        <div class="pd20 bg">
          <h4 class="title">House</h4>
        </div>
        <div class="panel-footer text-center">
          <button type="button" class="btn btn-warning btn-sm" ng-click="vm.clear()">
            <i class="fa fa-edit" aria-hidden="true"></i> clear</button>
          <button type="button" class="btn btn-warning btn-sm" ng-click="vm.submit()">
            <i class="fa fa-edit" aria-hidden="true"></i>Submit</button>
        </div>
      </div>
    </div>
  </div>
</div>
Tính Ngô Quang
  • 3,900
  • 30
  • 31