Using pure javascript, I wanted to click a button and trigger the events of it, but the important thing is that I do not want to call the function directly. So far I have tried this:
var send = document.getElementsByName("send");
window.addEventListener("keyup", function( e ){
if(e.which == 13 || e.keyCode == 13){
send.dispatchEvent(new Event('click'));
}
});
I have searched in several articles, but I need the equivalent of jQuery element.click();
, but the articles only teach to call the function directly interconnected to the element.
<button name="send" onclick="alert('foo')">Enviar</button>
Using pure javascript, as I clicked this button without being directly or calling the function that is in onclick