Issue
The purpose is to add space after executing focus on an input which have an id = "editor".
let editor = document.getElementById("editor") as HTMLElement;
editor.focus();
// here I want to add on the focused HTMLElement "body"
I try to dispatch a KeyboardEvent to add space or any letter but this didn't worked.
editor.dispatchEvent(new KeyboardEvent('keypress',{'key':'a'}))
Solution
You can try below code:
editor.addEventListener('focus', function(event){
if(!event.target.value){
editor.value = ' '
}
})
Answered By - N.SH
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.