Event delegate binding A ul, how to know which li is clicked in the ul

the content of li is the same. Is there any easier way to get the index of li

?
Sep.25,2021

  1. you can first get event.target
  2. I think we can directly refer to the .index () method of jQuery source code .
  3. if you use jQ, you can use $(this). Index () directly
  4. .

when rendering, just write it in the attr of li. It has to be processed in a loop when you get it, which is very inefficient.
most li renderings are cyclical and static. Forget it.


sibling framework can help you have API, such as the index () method mentioned above.

Menu