Search code examples
jqueryfocusblur

keep up mobile keyboard textarea always focus jquery


I'm making an instant chatting page chat.php, where once the user hits enter, the message is delivered to the conversation container. when this happens the textarea lose focus and the mobile keyboard goes down.

I've been searching how to keep textarea always focused but I coulnt find anything consistent.

Whit this code, once the user hits enter, the keybord jumps down and up.

  var textarea = $('#chatting');

       textarea.bind("blur", function() {
                setTimeout(function() {
                                textarea.focus();
               }, 0);
             });

Another solution given was to initialize with $('#chatting').focus(); but not results.


Solution

  • Don't do that with blur event. Sometimes people want to select another menu, etc.

    Just use after button send clicked. back to focus the textarea

    $('#button-send').click(function(){
    $('#chatting').focus();
    });