JQuery To Do List with delete confirm - but the question comes for all entrys, instead of one time. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

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>

10th Oct 2019, 12:35 PM
itsAnyTime
itsAnyTime - avatar
1 Answer
0
I changed it to id. But +(z++)? Can you try it and help me out? It's on my Profile: https://code.sololearn.com/WI1c5ZYndv2J/?ref=app
11th Oct 2019, 9:40 AM
itsAnyTime
itsAnyTime - avatar