Todo-list help (Beginner)

The entire thing works fine except that when you press the "delete" button, the entire list gets deleted. All listitems have their own delete icon and i want them to delete only that listitem.

$(document).on("click", "delete", function(e) {
    node.parentNode.removeChild(node);                                             
});

Full code

var TodoApp = (function (){

var clear = $("#clearButton");
var add = $("#addTodoButton");
var save = $("#saveButton");

function init (){ 
    
    clear.click(function(){localStorage.clear();
    location.reload();});

    save.click(function(){
    var todoList = $("#lista").html();
    localStorage.setItem("listItems", todoList)});
    
    add.on("click", addtodo);


    $(document).on("click", "delete", function(e) {
    node.parentNode.removeChild(node);                                             
});
    loadNotes();
}
    
    
function loadNotes(){
    var savedNotes = localStorage.getItem("listItems");
    if(savedNotes){$("#lista").html(savedNotes);}
}


var text1 = $('#todoText').val();

function addtodo(){text1 = $("#todoText").val();{
$("ul").append("<li>" + '<input type="text" value= "' + text1 + '">' + 
'<a href="" class="delete"><img src="bilder/red_x.png" </a></li>');
$("#todoText").val("")}};


return {init:init};

   
})();


TodoApp.init();
    

Posted Aug 23, 2017, 11:09 AM UTC

81
zedpowa•

node.parentNode.removeChild(node);

I don't see node defined anywhere in your code.

2