Article
    C#
    ADO.Net
    .NET
    ASP.Net & Web Forms
    Custom Controls
    Web Development
    Exception Handling
    XML
    Database
    Security in .Net
    Testing
    Web Services
    Windows Services
    Windows Controls
    WCF
    AJAX
    WPF
    XAML
    Reporting
    Setup
    VB.Net
    LINQ
    JQuery
    SilverLight
    JavaScript
    HTML5
    Crystal Report
    Cloud Computing
    Share Point
    Visual C++
    MVC
    Android
    PHP
    Java
    HTML
    WordPress
    Joomla
    Products
    Drupal
    Windows Phone
    JSON
    LightSwitch
    iPhone/iPad
    Ruby on Rails
    IIS 7
    Windows 8
    CSS/CSS3
    Excel
    MS Access
    Shortcut Keys
    Visual SourceSafe
    Team Foundation Server
    API(s)
    Sencha-Touch
    Single Page App
    Bootstrap
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Top Contributor
Advertisement
Advertise with Us
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog

Home >> JQuery >> JQuery each method
JQuery each method
JQuery each method


by Sachindra Singh on 2/21/2011 10:02:38 PM

Views: 2035       Comments: 0

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 ();

Code:

<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

                });

            });

 

        });

    </script>

 

</head>

<body>

    <h2>

        JQuery each method</h2>

    <table width="200">

        <tr>

            <td align="center">

                City List

            </td>

        </tr>

        <tr>

            <td>

                <select>

                    <option>Allahabad</option>

                    <option>Varanasi</option>

                    <option>Lucknow</option>

                    <option>Kanpur</option>

                    <option>Fridabad</option>

                    <option>Mumbai</option>

                    <option>Chandigarh</option>

                </select>

            </td>

            <td>

                <button>

                    Total Cities</button>

              

            </td>

        </tr>

    </table>

</body>

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

Screenshot

JQuery each method

 

Report Abuse Form
Reason:    
 

Title :
Comment :
Text ColorBackground Color
BoldItalicUnderline
LeftCenterRightJustify
Ordered ListBulleted List
IndentOutdent
Horizontal Rule
SubscriptSuperscript
HyperlinkImage
Design ModeDesign
View HtmlHtml
     
 
Latest Article by Sachindra SinghRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Latest BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Top Viewed ArticlesRSS Feed
    
    
    
    
    
    
    
    
    
    
Top Viewed BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
Latest Interview QuestionsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Total Online Users: 4693
Advertisement
MindStick DataConver
Advertise with Us
  
Copyright © 2014MindStick. All Rights Reserved.