This works in desktop safari, but in the iOS version no alert pops up. Is it possible to bind to the \'html\' element in iOS? I want to close a drop-down menu whenever the user
Use document
or body
element instead of html
$(document).bind("click", function(){
alert("clicked!")
});
You can also try this.
$('html, body').bind("click", function(){
alert("clicked!")
});
jQuery.click() doesn't function properly on iOS. I suspect that you're having the same problem with bind(). jQuery.delegate() however does work.
$('html').delegate('body', 'click', function(){ alert("body"); });
Should work for you. Presumably on() will also function, but I haven't had a chance to try it yet.
As an aside, you should move that script block below the body tag and lose the $(document).ready().
Update: In any recent vintage of jQuery, on(event, selector, function) is the way to go. It works on IOS and resists leaking event handlers.
$('body').on('click', ':not[#stuff]', function(){ alert("not stuff"); });