Is there a default way to trigger a click event anytime enter is pressed on a focused element?
What I am referencing is the differences from pressing enter while focused on a <button>
vs. pressing enter while focused on a <div> <li> <span>
, etc. The <button>
keypress enter
triggers as expected. However, <div>
keypress enter
does nothing. I believe you have to specifically write the event in for that keypress.
$('li').click(function() {
//toggles something
});
$("li").keydown(function(e){
if(e.which === 13){
$(this).click();
}
});