Answer the question
In order to leave comments, you need to log in
Why does the delete script in js not work?
The js removal script does not work, here is the code:
document.querySelectorAll('.delete').forEach((btn, i) => {
btn.addEventListener('click', () => {
btn.parentElement.remove();
movieDB.movies.splice(i, 1);
});
});
Answer the question
In order to leave comments, you need to log in
Try like this:
buttons = document.querySelectorAll('.delete');
for (var n = 0; n < buttons.length; n++) {
buttons[n].addEventListener('click', function() {
var delete_element = this.parentElement;
element.parentNode.removeChild(element);
movieDB.movies.splice(n, 1);
});
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question