Q:

How to assign enter key the same function as click?

I'm trying to have the enter key perform the same task as when a user clicks the button (see jquery). However, when I tried "keyup" and other event handlers, I couldn't get it working correctly. Any ideas on the simpliest way to do this?
Thanks for your patience, and help.
See fiddle: https://jsfiddle.net/LightYearsAway/qg8f3q37/3/
HTML
<h3>Needs</h3>
<input type="text" id="need-input" placeholder="enter text">
<button id="btn1">Need it!</button>
<ul id="need-list">
    <li>a</li>
    <li>b</li>
    <li>c</li>
    <li>d</li>
    <li>e</li>
</ul>

JS
$(document).ready(function(){

  // click button, add to list

  $("#btn1").click(function(){
      $("#need-list").append($("<li>", { text: $("#need-input").val()
      }));
  });

  // click list item to hide

  $('ul').on('click', 'li', function(event) {
      $(this).slideUp();
  });

});

A:

Try this:
$("#need-input").on("keydown", function(e) { 
    if(e.keyCode == 13)
        $("#btn1").click() 
});

https://jsfiddle.net/qg8f3q37/4/

