Problem with turning enter event into click event

Demo of problem where enter event was turned into click event, but this doubled the event firing in an edge case.

by Brenton Strine

HTML

<input type="text" value="focus here then tab down">
<div tabindex="0" id="item">Hit enter while this is focused.</div>
<input type="text" value="tab up">
<p>Tab to the text and hit enter. View the results in the console. You will see that because of the JS that turns [enter] into [click], you get both [click] and [enter] when you hit enter, thus firing the "toggle" twice, thus undoing the toggle.</p>

JavaScript

$("#item").on("keyup", function(event){
    if(event.keyCode == 13){$('#item').click();}
});

$('body').on('click keyup', '#item', function(e) {
    console.log("-----------------");
    if(e.type=="click") {
        console.log("Event Type: " + e.type);
        //toggle something
    } else {
        console.log("Event Type: " + e.type+ ", keyCode: " + e.keyCode);
        //toggle something
    }
});

// for reference:
// keyCode 9  = tab
// keyCode 13 = enter