Answer the question
In order to leave comments, you need to log in
How to do it in PURE js?
I need to hang a click event handler on each li from the ul menu:
(not stupidly on each individual element)
<ul class = "list">
<li class="li active">главная</li>
<li class="li">навыки</li>
<li class="li">опыт</li>
<li class="li">портфолио</li>
<li class="li">контакты</li>
</ul>
Answer the question
In order to leave comments, you need to log in
Here is a small sandbox example using old JavaScript.
Link to the sandbox
I don’t advise hanging on each element of the list, because there can be a lot of them and this will have a bad effect on performance, so there is such a thing as event delegation, this is when we hang 1 listener on the parent element and check where the click was made. This is exactly what is done in the sandbox example.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question