Accessing objects using index in jquery
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.
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.
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 ?
Use each!
$('.copy_anim').each(arr,function(){
$(this).css({
'position' : 'relative',
'right' : '-30px',
'opacity' : '0'
});
});
精彩评论