tags:

views:

143

answers:

2

How do you iterate through a group of selected jQuery objects so that you can perform jQuery functions on each object individually?

   
 <div class="foobar">abc</div>
 <div class="foobar">123</div>
 <div class="foobar">abc123</div>

I can select the group:

var foobarObjects = jQuery('.foobar')

But how would you go through each jQuery object in foobarObject and manipulate each one individually? I thought I could use jQuery().each but that only allows me to work with DOM objects, not jQuery objects. I also tried a for loop in conjunction with the jQuery().eq(i) function, but that seems to merge the items together.

+1  A: 

within jQuery().each() you can use $(this) to use the jQuery functions on the current DOM object.

Ty W
+5  A: 

Use $(this)

$('.foobar').each(function(){
  $(this).blah//refers to jquery object.
});
Stefan Kendall
B.T.W. if you need to set something like attribute or class on ALL items in group you can simply use $('.foobar').attr("blah", "blah");
DroidIn.net
Excellent! Just what I needed. Thanks!
JayNCoke