Home > DeveloperSection > Articles > JQuery each method

JQuery each method

Posted by  Sachindra Singh
on    February-21-2011 22:02 PM

JQuery JQuery 
0 Comment(s)
 3243  View(s)
Rate this:

JQuery each method

The $.each () function can be used to iterate over any element collection. This function runs on the matched element. The each () method specifies a function to run for each matched element. In this example I am using each method to show each city name that defined in <option> element.

Syntax: $(“target”).each ();


<title>JQuery each method</title>


    <script type="text/javascript" src="jquery.min.js">     </script>


    <script type="text/javascript">

        $(document).ready(function() //ready function contain all jquery function


            $("button").click(function            {

                $("option").each(function()// each method will retrieve all city name that define in <option> element


                alert($(this).text()); //this line will show city name










        JQuery each method</h2>

    <table width="200">


            <td align="center">

                City List

















                    Total Cities</button>






When I will click on city button the name of city will popup on window as shown below:


JQuery each method


Recent Activities

Glen Martin Created New Discussion Modifying NSDate to represent 1 month from today   14 hours ago

Glen Martin added new Question Difference between shallow copy and deep copy?   14 hours ago

ashish srivastava added new Article Article Submission Process   3 days ago

Manoj Pandey added new Blog Android Studio Vs Eclipse   7 days ago

Don't want to miss updates? Please click the below button!