Try It Editor
Tip: Press
Ctrl/⌘ + Enter
to Run
▶ Run
Reset
Copy
Download
Code
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>index()</title> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> </head> <body> <ul id="list"><li>One</li><li class="pick">Two</li><li>Three</li></ul> <button id="where">Get index of .pick</button> <script> $("#where").click(function(){ alert( $(".pick").index() ); // 1 }); </script> </body> </html>
Output