JQuery To Do List with delete confirm - but the question comes for all entrys, instead of one time.
How can I modify the code, that the confirm question only happens one time? <!doctype html> <html> <head> <meta charset="UTF-8"> <script src="https://code.jquery.com/jquery-3.1.1.js"></script> <title>To Do List</title> </head> <body> <h1>My To Do List</h1> <input type="text" placeholder="New item" /> <button id="add">Add</button> <ol id="mylist"> </ol> <script> $(function() { $("#add").on("click", function() { // get input var val = $("input").val(); // if form is not empty if(val !== '') { // create list item var elem = $("<li></li>").text(val); // append x button after list element $(elem).append("<button class='rem'>X</button>"); // append element on mylist $("#mylist").append(elem); //clears the input $("input").val(""); // handle the click event on class rem $(".rem").on("click",function() { // ask for confirmation let cont = confirm('Continue?'); // if pressing ok if(cont) { // deletes the selected x value $(this).parent().remove(); return true; } // otherwise cancel. event.preventDefault(); }); } }); // enter to submit, instead of pressing add $("input").keyup(function(event){ if(event.which==13){ $("#add").click(); } }); }); </script> </body> </html>