jquery each method

the jquery $.each() method specifies a function to execute for each matched element.

the jquery each method syntax :-

     $(selector.each ( function( index, element ) )
parameterdescription
function(index, element)required. a function to run for each matched element.

  • element :- indicate the current element.
  • index     :- index position of the selector.

jquery each method example

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