1

i am making a website for mobile devices, in which i have a list of name and i need to bind click event to the list. i done this using jquery. in all webdevices (android, blackberry, nokia) when i click the list the result will come but nly in iphone the event is not triggering. how can i solve it.

<ol id="movie-list">
 <li> Movie 1 </li>
 <li> Movie 2 </li>
 <li> Movie 3 </li>
</ol>

$('#movie-list li").live("click", function() {
 console.log($(this).html());
});
Jaison Justus
  • 2,753
  • 8
  • 47
  • 65

2 Answers2

2

http://bugs.jquery.com/ticket/5677 - Live Click Events Don't Register On MobileSafari (iPhone)

Apparently that's a jQuery bug. "The workaround is to add onclick="" to the element you are attaching to...."

On a different note though, .live() has been deprecated.

The link provides information on porting to newer methods. If using jQuery 1.7+:

$(document).on("click", "#movie-list li", function() {
    console.log($(this).html());
});
nbrooks
  • 18,126
  • 5
  • 54
  • 66
1

Use jquery .on instead of .live

There is typo in your code '#movie-list li" should be "#movie-list li"

$(document).on("click", "#movie-list li", function() {
   alert($(this).html());
});

EDIT: Exact duplicate - How do I use jQuery for click event in iPhone web application

Community
  • 1
  • 1
Dipak
  • 11,930
  • 1
  • 30
  • 31
  • @JaisonJustus check the duplicate answer I posted :) – Dipak Jul 18 '12 at 06:56
  • 1
    @jaison like I said in my answer, this is a known problem. Some elements aren't allowed to trigger clicks in mobile safari. I provide a workaround in my solution... – nbrooks Jul 18 '12 at 07:01
  • i added cursor : pointer to the style of li. now its works fine. testing on devices.. thank you Dipaks and nbrooks – Jaison Justus Jul 18 '12 at 07:02