S
S
Swaer2018-03-27 17:38:39
JavaScript
Swaer, 2018-03-27 17:38:39

I can not understand and parse the code, help?

const spans = document.querySelectorAll('span');
for(let span of spans){
    span.addEventListener('click', function(e){
     e.target.parentNode.removeChild(e.target);
    })
}

I can’t understand why there is a const here (I think it’s a whim of the author), for (let span of spans) I can’t understand how it works and where you can read about it, I meet for the first time, then I realized that I attached the event to the span, when I clicked it, I called the function function (e ), what is the 'e'?, further on the mouse target it works and deletes the child element without specifying the parent, correct my mistakes and answer the questions =)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AHDPEu, 2018-03-27
@AHDPEu

const - constant, immutable variable. In this case, this is a whim of the author of the
e - event object, it contains information about the event and the element on which it worked
. for..of
Deletes itself, since we find the parent from the current element (.parentNode) and delete the child from this parent, that is yourself (e.target)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question