jquery index method

the jquery $.index() method is used searching for a given element from among the matched elements.

note :- if the element not found index method return -1 value.

get the index position of the first matched element relative to its sibling elements.

the jquery index method syntax :-

      $(selector.index ()

get the index position of an element relative to the selector.

     $(selector.index ( selector )
parameterdescription
selectoroptional.the selector can be dom element or a jquery selector.

the jquery index method example

             <script>
               
                   $(document).ready(function(){
                   
                   $("li").click(function(event){
                   
                   alert("li index value :--"+$(this).index());
                   
                        });  });   
                        
               </script>