What I want to achieve is, when hovering over the li with id="a", the corresponding ul with id="aa" appears. I have this html code:
<ul>
<li id="1">Option1</li>
<li id="2">Option2</li>
</ul>
<ul id="11">
<li>Option1.1</li>
<li>Option1.2</li>
</ul>
<ul id="22">
<li>Option2.1</li>
<li>Option2.2</li>
</ul>
and this javascript code:
for (i=1; i<3; i++) {
var fn = (function(i) {
var li = document.getElementById(i);
var ul = document.getElementById("" + i + i);
li.addEventListener("mouseover", function() {
ul.style.opacity = "1";
}, false);
})(i);
}
and it works as expected, but here the user Jordan Gray stated that it is possible to get rid of the loop and instead create one event listener for all list items - that is what I would like to achieve here. Unfortunately I do not understand his code and would be thankful if anyone could explain it to me or suggest a solution.