I'm new to React.js. I'm trying to trigger keypress event for text div.
Here is text box code for which I want to execute keypress trigger.
<div id="test23" contenteditable="true" class="input" placeholder="type a message" data-reactid="137">Hii...</div>
and keypress method is:
onKeyPress: function(e) {
return "Enter" == e.key ? "Enter key event triggered" : void 0)
}
I tried it with jQuery but I can't trigger it.
Here is my React code that I tried but its not working:
var event = new Event('keypress', {
'keyCode' : 13,
'which' : 13,
'key' : 'Enter'
});
var node = document.getElementById('test23');
node.dispatchEvent(event);