I have this error showing on my console although everything is working fine, I have divs of books name, and beside them a button “delete. at the bottom I have a form with the button “add”, I am trying to add and delete books according to event “click” and it works fine, but I’m wondering what this error means? “script.js:9 Uncaught TypeError: Failed to execute ‘removeChild’ on ‘Node’: parameter 1 is not of type ‘Node’. at HTMLDivElement. (script.js:9)”
Advertisement
Answer
Try switching around the .removeChild()
function like below:
JavaScript
x
7
1
booklist.addEventListener('click', function(e){
2
if(e.target.className == 'rem') {
3
var bookdiv=e.target.parentElement;
4
bookdiv.removeChild(booklist);
5
}
6
}
7
Another approach is to delete the bookdiv
.
JavaScript
1
7
1
booklist.addEventListener('click', function(e){
2
if(e.target.className == 'rem') {
3
var bookdiv=e.target.parentElement;
4
bookdiv.remove();
5
}
6
}
7