O
O
Ostap Bellik2021-06-12 20:07:25
JavaScript
Ostap Bellik, 2021-06-12 20:07:25

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

1 answer(s)
N
Nadim Zakirov, 2021-06-12
@Ost123

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 question

Ask a Question

731 491 924 answers to any question