Removing items from a to do list using Javascript

前端 未结 3 870
一整个雨季
一整个雨季 2021-01-07 07:31

Attempting my first Javascript project, playing around with DOM to make a To-Do List. After adding an item, how do i get the \'Remove\' button to function and remove the ite

3条回答
  •  有刺的猬
    2021-01-07 08:08

    Use this

                  // +your code 
                 .....
                 node.appendChild(removeTask);
                    // + modify
                    removeTask.onclick = function(e){
                        var dom = this;
                        var p_dom = this.parentNode;
                        console.log(p_dom);
                        var parent_node = p_dom.parentNode;
                        parent_node.removeChild(p_dom);
                    }
    

提交回复
热议问题