You see, what I need is to know when an element has activated an event, it has its respective EventListener, but there are several elements that have that Listener, so how do I know which of all the elements was the one that activated the event?
(function(elementos){
for (var i = 0; i < elementos.length; i++) {
elementos[i].addEventListener("click", marcar(), false);
}
})(document.getElementsByTagName("a"));
HTML:
<body>
<div class="nota">
<span><h1>Tareas</h1></span>
<div class="actividades">
<ul>
<li><a href="#">Levantarme</a></li>
<li><a href="#">Cepillarme</a></li>
<li><a href="#">Comer</a></li>
<li><a href="#">Bañarme</a></li>
</ul>
</div>
</div>
</body>
As you can see, I pass a series of "a" elements to the function, to which I add an EventListener to each one with a "for", so if I wanted to know which of all the "a" elements activated the event, What could I do?
In order to identify which element triggered an event, you can use event delegation:
click
for exampletarget
that would return a large amount of information; where to find out you can use:className
id
innerText
Example
If you want to see all the information you can get, I recommend that you print to the console using the following instruction:
Within the context of the provided code
Reference Documents