0

我想将一些 CSS 应用于所有以前的图像标签。

$('#'+globe).prevAll().removeClass('t2').addClass('t1');

这是将 CSS 应用于所有先前的元素,包括div.

它怎么能仅限于img元素?

4

3 回答 3

3

改变

$('#'+globe).prevAll().removeClass('t2').addClass('t1');

$('#'+globe).prevAll('img').removeClass('t2').addClass('t1');

或者

$('img',$('#'+globe).prevAll()).removeClass('t2').addClass('t1');
于 2013-05-28T12:02:18.590 回答
2

你为什么不只使用css。

img{
  style here for all images
}
img:last-child{
   different style for last image
}
于 2013-05-28T12:03:10.843 回答
0
  $('#'+globe).prevAll('img').removeClass('t2').addClass('t1');
于 2013-05-28T12:03:18.413 回答