多个存储元素.css()

multiple stored elements .css()

本文关键字:css 元素 存储      更新时间:2023-09-26

我有这个jQuery代码:

nextimg = $('.index-slide-container img#' + next);
nextcaption = $('.index-slide-container .index-slide').filter('#'+next);
nextimg.css({
    'left':'100%',
    'z-index':'99'
});
nextcaption.css({
    'left':'100%',
    'z-index':'99'
});

我想知道如果你能以某种方式组合/链两个。css函数成一个?

可以使用jQuery的add()函数:

nextimg.add(nextcaption).css({
    'left':'100%',
    'z-index':'99'
});