How can I submit with button and Enter in Jquery?
Which is the best way to add a keypress function to call a click function? If there is a better way to get this done please let me know as I ma new to jquery. Here's my current code: $(function(){ $("#add").click(function() { var val = $("input").val(); if (val !== ''){ var elem = $("<li></li>").text(val); $(elem).append("<button class='rem'>X</button>"); $("#myList").append(elem); $("input").val(""); $(".rem").on("click", function(){ $(this).parent().remove(); }); } }); $('#add').keypress(function(e){ if(e.which == 13){ $('#add').click(); } }); });