0

I'm using jquery 1.8.3 and I am doing a .live call

   $('.ui-state-default').live('click', function(e) {
        $(".upload").show();
    });

Using my iPhone iOS 6.1 I cannot click on this dom element.

Why doesn't iOS understand .live?

I switched my code around to this.

$('.ui-state-default').bind('click', function(e) {
    $(".upload").show();
});

But now I have another issue, is there a way to make iOS understand the first piece of code with .live?

Blynn
  • 1,411
  • 7
  • 27
  • 48
  • Are you sure you're using 1.8.3? `.live()` was deprecated in 1.7 and removed in 1.9. It should still be there in 1.8. But you shouldn't use it. – Barmar May 06 '13 at 15:52
  • Well I guess I'll have to work out the other issues, with not using .live() – Blynn May 06 '13 at 15:56
  • Use `.on()` as described in the answers. – Barmar May 06 '13 at 15:57
  • You say this is a problem with iOS, have you tried it in a normal browser? i suspect you will have the same issue, and it will be due to the plugin/widget stopping the propagation of the event. – Kevin B May 06 '13 at 15:59
  • 1
    Chrome still works with .live in jQuery 1.8.3. I'm probably going to have to start using .on() – Blynn May 06 '13 at 16:02

2 Answers2

2

Well, live has been removed anyway in newer builds of jQuery, so I'd just get used to using it differently anyway.

$('body').on('click', '.ui-state-default', function(e) {
    $(".upload").show();
});

body can be replaced by anything guaranteed to be there on document ready that contains the .ui-state-default elements. Body will always be present, but perhaps you have something more specific you can use if you'd like.

Also, you probably don't really want to use 'click' on iOS, 'touchstart' might be a better choice. (but do some research rather than just dropping that in!)

Rich Bradshaw
  • 71,795
  • 44
  • 182
  • 241
1

Use .on() as .live() is deprecated, bind click and tap events:

$(document).on('click tap', '.ui-state-default', function(e) {
    $(".upload").show();
});
A. Wolff
  • 74,033
  • 9
  • 94
  • 155