I have the following sample code:
ul = document.getElementById("list");
li = document.querySelector("#list li");
cuerpo = document.body;
ul.addEventListener("click", function(event) {
console.log("Clicked on ul");
});
li.addEventListener("click", function(event) {
console.log("Clicked on li");
});
<ul id="list">
<li>one</li>
<li>two</li>
<li>three</li>
</ul>
That I'm using it to understand the Event Propagation process. As it is bubbling by default, it should show the console.log message ("Clicked on li"); and then that of ul. But it does not, it only shows that of ul.
If I do the same with other HTML elements, the propagation works correctly. So for me the problem is in the document.querySelector argument. The information from MDN or from W3C itself made me very complex. So I would appreciate it if you could tell me if "#list li"
is a valid argument and if not, in what way I could achieve what I set out to do.
EDIT: I've noticed that only the first li responds to the event.