tags:

views:

18

answers:

3

How can I access Objects when there are multiple objects are returned when using selectors?

     $('.copy_anim')[i].css({
      'position' : 'relative',
      'right'    : '-30px',
      'opacity'  : '0'
     });

using the above code says $('.copy_anim')[i].css is not a function.

A: 

If I understand well, you don't know the $.each in jQuery...

$('.copy_anim').each(function(index) {
    $(this).css({
      'position' : 'relative',
      'right'    : '-30px',
      'opacity'  : '0'
     });
  });

Is that it ?

Chouchenos
And you can use index or whatever you called it, to choose which one you want to modify, etc... Here's the doc : http://api.jquery.com/each/
Chouchenos
A: 

Use each!

$('.copy_anim').each(arr,function(){
  $(this).css({
   'position' : 'relative',
   'right'    : '-30px',
   'opacity'  : '0'
  });
});
Hannes
+2  A: 

If you want the jQuery object (so you can use .css()) on the element at the i (0-based) index, use .eq() like this:

$('.copy_anim').eq(i).css({
  'position' : 'relative',
  'right'    : '-30px',
  'opacity'  : '0'
 });

If you just want to run it on all of the elements, just do:

$('.copy_anim').css({
  'position' : 'relative',
  'right'    : '-30px',
  'opacity'  : '0'
 });

This will run the .css() on all .copy_anim elements...this is the default behavior of jQuery.

Nick Craver