Stripe class for div

风格不统一 提交于 2019-12-01 18:03:47

$('.xyz:odd').addClass('grey');

Do mind that 'grey' is not a semantic classname. Better call id 'odd' or 'zebra' or something. If you'd make up your mind and change the odd color to blue your classname would be real strange :P

jQuery makes it just about as easy as it can be:

$('#main>div.xyz:even').addClass('grey');

http://api.jquery.com/even-selector/

If you don't care about older versions of IE, you can do this using CSS alone:

.xyz:nth-child(odd) {
  background-color: ...;
}

.xyz:nth-child(even) {
  background-color: ...;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!