.each( function(index, Element) ) :- execute for each matched element

It will Iterate over a jQuery object, executing a function for each matched element.

When we need to apply some index number to some elements iteratively, we can assign it using .each method. This method is useful when we need to assign some common property to number of repeated divs or list.

Example :-

<ul>
<li>Monday</li>
<li>Tuesday</li>
<li>Wednesday</li>
</ul>
<script type=”text/javascript” src=”jquery.js”></script>
<script type=”text/javascript”>
$(‘li‘).each(function(number) {
alert(number + ‘: ‘ + $(this).text());});
</script>

Output :-

0: Monday
1: Tuesday
2: Wednesday

This method assign index number starting from 0 to number of elements.

Advertisements

I like to hear from you about this !!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s