JSFiddle - React, Tailwind, and code Playground
by AlienWebguy
HTML
<p>
To test the keypress event, click anywhere in this frame and hit the tab key to focus the button, then press a key. <br /><br /> </p>
<p>
Dummy text
</p>
<p>
<button id="save">Here is the test link</button>
</p>
<p>
Dummy text
</p>
JavaScript
document.getElementById('save').addEventListener('mousedown', function(){submitData(event, this);});
document.getElementById('save').addEventListener('keypress', function(){submitData(event, this);});
function submitData(event, id) {
if (event.type == 'mousedown') {
// do something
alert('the mousedown event');
return;
}
if (event.type == 'keypress') {
// do something else
alert('the keypress event');
return;
}
}