jQuery a method that displays an li index number in ul
- 2020-05-16 06:24:48
- OfStack
This example shows how jQuery displays an li index number in ul. Share with you for your reference. The specific analysis is as follows:
This code applies not only to element index number look-ups for ul and li, but also to other element index number look-ups with containment relationships, in a very clever way
$("ul > li").click(function () {
// //www.ofstack.com
var index = $(this).prevAll().length;
//prevAll([expr]): Find all peer elements before the current element
});
I hope this article has helped you with your jQuery programming.