Reputation: 1096
When I press enter, I want to reset the textarea, but when I do that there is a problem.
Example:
'Typ hier om te chatten' is the placeholder. When I typ something an hit enter:
Now it is focused, but I still need to click to type again, how to do this automaticly?
Code:
$(document).keypress(function(event){
var keycode = (event.keyCode ? event.keyCode : event.which);
if(keycode == '13' && $( "#message" ).val().trim() != ""){
socket.emit("sendMessage", { value: $( "#message" ).val() });
$( "#message" ).remove();
$( "#messagesBoard" ).append("<textarea autofocus maxlength=\"308\"id=\"message\" placeholder=\"Typ hier om te chatten\"></textarea>");
$( "#message" ).click(); << WONT WORK
}
});
Upvotes: 0
Views: 372
Reputation: 176896
can you try like this , which will set focus on textarea
once it get created
setTimeout(function() {
$( "#message").find('textarea').focus();
}, 10);
Upvotes: 1