Jquery keyup not working on Android
Asked Answered
C

2

9

i didn't tested this code on iPhone but i'm sure (tested) it doesn't works on android mobiles:

 $('#search').live('keyup',function(key){
          if(key.which == 13){
            /*ANIMATE SEARCH*/
            _key = $(this).val();
            $("#wrapper").html("");
                $('#wrapper').hide(0).load('results.html').fadeIn(800);
                $('#search-fade').val(_key).fadeIn();
          }
      });

to explain better :

i have a simple

<input type="text" name="search" id="search"/>

don't know why but this code doesn't works properly on android mobile phones

any ideas?

Cherlycherlyn answered 14/5, 2012 at 9:2 Comment(2)
you should try on() instead on live(), cause live() is deprecated.Triviality
I have reviewed the available information and changed my answer.Placative
T
10
$(document).on('keyup','#search', function() {
   // code
});

or

$(document).delegate('#search', 'keyup', function() {
    // code
});

You can also see here

Triviality answered 14/5, 2012 at 9:20 Comment(2)
Should be "delegate" not "delegete", in case anyone comes across this solution.Ryle
Hm I tried this and its not working for me. Is there a better solution now?Graniah
P
5

My solution (working with jQuery 1.7.1):

$('#search').live('input paste', yourFunction)

Tip:

Use .on() instead of .live(), because:

  • .on() is faster
  • .live() is deprecated

jQuery 1.7+ .on() vs .live() Review

Try this:

$(document).on('input paste', '#search', yourFunction)
Placative answered 16/5, 2012 at 19:34 Comment(1)
really not solve i still having this trouble cause input inside collapse is ok and event is binded while input in same page but not in collapse menu shows me the arrow instead of the search button in android keyboard :/Cherlycherlyn

© 2022 - 2024 — McMap. All rights reserved.