I have simply an unordered list am trying to create with html5 and javascript, I want to add events to this list element eg first element.
Here is my HTML list:
<ul class="aside__list">
<li class="one">Kutomba kuma</li>
<li class="two">Kutomba tako</li>
<li class="three">Kutomba mkundu</li>
<li class="four">Kutomba malaya</li>
</ul>
JS:
var parentElements = document.getElementsByClassName('aside__list');
for (var i=0; i<parentElements.length; i++) {
parentElements[i].addEventListener('click', doStuff, false);
console.log(parentElements[i]);
}
function doStuff() {
alert('Delete me');
}
I want to add an event to the first element of my list using for loop without using a class or id, now this event applies to every list element in my list,
what do I need to change to get what I want?