When you press a key, it should output the contents of the input field to the console, but in fact it displays one less character than necessary.

document.onkeypress = function(){ var text = document.getElementsByClassName("im_editable im-chat-input--text _im_text"); var input = text[0].innerText; console.log(input); } 

Example: “Hello” is entered - “Prive” is displayed.

  • the symbol is not yet in innerText . Use keyup . - Igor
  • @igor thanks a lot - WsQ

1 answer 1

The symbol is not yet enrolled in the item. Use keyup .

 document.querySelector("textarea").onkeypress = function() { console.log("keypress: " + document.querySelector("textarea").value); } document.querySelector("textarea").onkeyup = function() { console.log("keyup: " + document.querySelector("textarea").value); } 
 <textarea></textarea> 

  • Thanks, it works well through keyup - WsQ