我想将一些 CSS 应用于所有以前的图像标签。
$('#'+globe).prevAll().removeClass('t2').addClass('t1');
这是将 CSS 应用于所有先前的元素,包括div
.
它怎么能仅限于img
元素?
改变
$('#'+globe).prevAll().removeClass('t2').addClass('t1');
到
$('#'+globe).prevAll('img').removeClass('t2').addClass('t1');
或者
$('img',$('#'+globe).prevAll()).removeClass('t2').addClass('t1');
你为什么不只使用css。
img{
style here for all images
}
img:last-child{
different style for last image
}
$('#'+globe).prevAll('img').removeClass('t2').addClass('t1');