0

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.

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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 ?

1 Comment

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

Use each!

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.